mobile number length based on the country name selected in the dropdown [duplicate] - c#

This question already has answers here:
RegEx for valid international mobile phone number [duplicate]
(6 answers)
Closed 9 years ago.
In my asp.net application, I have to use the validation for mobile number length based on the country name selected in the dropdown.
I have googled for the solution, but couldn't able to find exact one.
Can anybody share the usefull link or info to me?

Short answer:
You can't (unless you're limited to a very specific subset of countries).
Long answer:
Telephone systems are too varied and - in short - non-standardized to create one "catch all" solution.
While some countries, like the US, got fixed length numbers, others, e.g. Germany, got variable lenghts.
For example, the area code for landlines in Germany is always 5 digits long (4 digits if you're calling from another country). However, for mobile phones it's always 4 digits (3 digits calling from another country).
The actual (local) phone number then can be anything from 3 digits up to 7 or more.
My parents have a telephone they've got ages ago - 4 digits (9 digits total with area code). If I'd get a new contract today, I'd most likely end up with 6 or 7 digits (12+ digits total).
What you could do
Rather than checking for complete numbers, you could try to use a regular expression (see Shekhar's comment above) to verify a proper formatting (e.g. to include the country selection). While this isn't a perfect solution, it should help you avoiding confusing input users left by accident.

Related

How to add zeroes Infront of an integer in c# [duplicate]

This question already has answers here:
Convert integer to binary in C#
(22 answers)
C# convert int to string with padding zeros?
(15 answers)
Closed 2 days ago.
I have a data I'm getting using my form and then I need to send it to a different software as an 8 digits number (in binary) the problem is the zeroes that come before the first '1' to appear in the data disappear.
for example:
the number 3 in binary is 00000011 so what will be send is 11
the letter A in binary is 01000001 so what will be send is 1000001
I need a code that will recognize how many digits in my data and add zeroes in front until the number would be 8 digits in c#
I looked online but all I could find is adding two known integers together but since I don't know how many digits would be missing from my data (as I don't know what the data would be yet, depends on the user), I can't use that.

Convert Numerical Digits in Vocabulary Forms [duplicate]

This question already has answers here:
How can I convert an integer into its verbal representation?
(16 answers)
Closed 7 years ago.
How can I convert final amount of billing to it's related vocabulary form?
I am trying to develop a function which convert it in vocabulary form.
For, ex. 12345 Rs. then it's output should be like this
TWELVE THOUSAND THREE HUNDRED N FORTY FIVE ONLY
is it possible with few easy steps in C# ?
If you are willing to use an external library, i'd suggest you try out Humanizer
Really simply to use and your example would be as simple as.
12345.ToWords(); //it adds extension methods that achieve this.

How to convert numerical value to words? [duplicate]

This question already has answers here:
How can I convert an integer into its verbal representation?
(16 answers)
.NET convert number to string representation (1 to one, 2 to two, etc...)
(11 answers)
Closed 8 years ago.
Hey anyone know about a function in C# that converts numerical value in to words
Like If I give Input: 53904
Then the output should be: FIFTY THREE THOUSAND NINE HUNDRED FOUR ONLY
By far, the best solution for this is the .NET Humanizr. It installs a series of extension methods and you can use it just like this:
15.ToWords(); // Returns "Fifteen"
int i;
i = 1587;
i.ToWords(); // Returns "One Thousand Five Hundred and Eighty Seven"
This works not only for numbers, but it works on DateTime, TimeSpan, Enums and others. I have used it in one of projects and it works great!
In addition, it has several other language translations, so it'll work in other languages, if you need it to.

Format number with comma separator for thousands using C# [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
String.Format an integer to use 1000's separator without decimal places or leading 0 for small integers
The blog post
http://blog.stevex.net/string-formatting-in-csharp/
(in the Custom number formatting section) shows that using the format {0:0,0}, a number like 1500 will be formatted as 1,500 which is good. But I don't understand why 0 is formatted as 00
Do I need to handle the case of 0 separately which doesn't seem to be necessary.
You can use "F0", which is "fixed number with 0 decimal places". It give you a thousands separator when you results go over 1,000.

Validate a UK phone number [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How do I validate a UK phone number in C# using a regex?
The regex in the accepted answer does not match all valid UK numbers, as it is too restricive (additional number ranges have been opened up in the meanwhile such as 0203, which it sees as invalid).
UK phone numbers follow fairly simple rules:
They can be either 10 or 11 digits long (with the exception of some special numbers, but you're unlikely to need to validate those)
They consist of an area code followed by a local number. The area code varies in length between three and five digits, and the local portion of the number takes up the remaining length of the 10 or 11 digits. For all practical purposes, no-one ever quotes just the local portion of their number, so you can ignore the distinction now, except for how it affects formatting.
They start with zero.
The second digit can be anything. Currently no valid numbers start with 04 or 06, but there's nothing stopping these ranges coming into use in the future. (03 has recently been brought into use)
They can be formatted with a set of brackets and with spaces (one or more, in varying positions), but those are all entirely optional.
Therefore, a basic working expression for UK phone numbers could look like this:
/^\(?0( *\d\)?){9,10}$/
This will check for 10 or 11 digit numbers, starting with a zero, with formatting spaces between any of the digits, and optionally a set of brackets for the area code.
(and yes, this would allow mis-matched brackets, as I'm not checking that there's only one closing bracket. Enforcing this would make the expression a lot more complex, and I don't have time for this right now, but feel free to add this if you wish)
By the way, in case you want to do additional filtering, you might want to also note the following rules:
Numbers starting 08, 09 and 070 are special price numbers, and would not generally be given as private numbers, so can be excluded if validating a private number.
07 numbers are mobile (except 070; see above) so can be excluded if you're specifically validating for a landline.

Categories

Resources