asp.net regular expression validator for email or numeric - asp.net

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]

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.

Regular expression for multiple words on Google forms validation

Simply I would like to add some answers that can't be answered by the submitter or user
I want a Regular expression for multiple words on Google forms validation
How to write a regular expression or a pattern for that matter
I've tried that
(Student Name 1|Student Name 2|Student Name 3)
With and without brackets
And the response just prevent the whole string like it isn't a regular expression

ASP.Net Validation Expressions for Phone Numbers

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}$"

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

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