ASP.Net Validation Expressions for Phone Numbers - asp.net

I need a Validation Expression to validate an Egyptian mobile number as an input in my form.
Egyptian Mobile Number:
must Contain 11 Digits
must Begin with '01'
the third digit must be either '2' or '1' or '0'

Do you need to support starting '+' characters, spaces or '-' signs inside your phone number? If you don't and you need to support just exact what you said then you can use this pattern:
"^01[0-2][0-9]{8}$"

Related

ASP.NET RegularExpressionValidator False Trigger

I'm validating a password that must be letters and digits with at least one digit and one upper case letter. I am using the following RegEx expression to do so:
(?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z])
Using this pattern, the password "Valid101" should be valid and it worked as expected at both A Better .NET Regular Expression Tester and REGEX TESTER. But, when I use it in my ASP.NET user control's RegularExpressionValidator it wrongly decides that password "Valid101" is not valid.
I'm hoping someone could suggest what might be wrong.
The pattern you have only consists of zero-width assertions, of lookaheads. They do not consume the text they match, so the match value after the regex matches is an empty string. The RegularExpressionValidator requires a full string match (i.e. the string matched should be the whole input string).
So, instead of (?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z]) use
^(?=.*\d)(?=.*[A-Z])[a-zA-Z0-9]{6,16}$
It will assure there is a digit and an uppercase ASCII letter in the string, and then will match (consume) 6 to 16 ASCII letters and digits.

Regex valid numbers with thousand separator

I'm doing a validation in asp.net textbox, and the textbox only allows user to input number
i.e.
valid numbers:
1234
12.345
12,345,678.231
12,345,678
invalid numbers:
-1234
12.23.45.67
12,
12,34,56
12,345,6
I'm trying to use a regex to validate the user's input on client side with the below regex:
^(?=.+)(?:[1-9]\d*|0)?(?:\.\d+)?$
The problem is:
the above regex only consider below as valid:
1234
12.345
How to modify the above regex to check if the thousand separator being entered into the correct place or not?
this seems to work ^\d+(,\d{3})*(\.\d+)?$
Demo

Identify number "type" by length, grouping, etc

Let's assume there's a text box somewhere on the page. Users can enter any number of any length, with spaces, hyphens, parentheses, etc. to define groupings. The system returns a list of what kinds of numbers that specific format could match. That is, an input of "111-11-1111" would return, among anything else applicable, "Social Security Number"; an input of "(111) 111-1111" would return "Canadian/American phone number"; an input of "1111 1111 1111 1111" would return "Credit card".
The implementation of this would be trivial, but is there a giant list out there of different number formats?
I think you need to write regular expressions for each type of number and if that regular expression matches than return the type name. You can find lots of regular expressions for SSN, phone number and credit card number on internet.
Check this thread for phone number regular expression.
Phone Number Regular Expression

asp.net regular expression validator for email or numeric

Is it possible use a regular expression validator for a textbox which accepts either user email or phone number (11 digits number which begins with 09) ?
so one regex is needed which accepts one of two cases, email or number.
For Email : "\w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)*"
[0][9][0-9]

regular expression for a text box that is not required, but needs to validate if entered

On my form I have a text box for a phone number. I have a regular expression that is fairly universal & can accept almost every variation for a phone number, local or international. the expression is as follows:
^((+)?[1-9]{1,2})?([-\s.])?(((\d{1,4}))|\d{1,4})(([-\s.])?[0-9]{1,12}){1,2}(x?[0-9]{1,})?$
The issue is, the field is not required, but needs to be validated if they decide to enter a number. is there any possible way of doing this?
Surround the entire regex, except the ^ and $ with an extra ( )?
^(((+)?[1-9]{1,2})?([-\s.])?(((\d{1,4}))|\d{1,4})(([-\s.])?[0-9]{1,12}){1,2}(x?[0-9]{1,})?)?$
I don't do ASP programming, but couldn't you do some sort of condition that says something like:
if( textbox.value.length > 0 ) then validate
So it only validates if the user entered something

Resources