asp.net email validation regex - asp.net

I want to validate email in asp.net RegularExpressionValidator where email id is
abc
abc.def
abc_def
I have tried
[0-9a-zA-Z]+([_]{0,1})|([.]{0,1})[0-9a-zA-Z]+
but the or condition doesn't work. It always fails for 2nd condition.
can anyone help me?

Put the second pattern inside a group and make it as optional.
^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)?$
DEMO

[0-9a-zA-Z]+[._]?[0-9a-zA-Z]*
You can simply do this instead.See demo.
https://regex101.com/r/cK4iV0/31
For yours to work you can do
[0-9a-zA-Z]+(?:(?:[_]{0,1})|(?:[.]{0,1}))[0-9a-zA-Z]*
See demo.
https://regex101.com/r/cK4iV0/32

Related

ASP.NET ValidationExpression to ignore case sensitivity

I currently have the following validation expression for one of my asp.net controls, which ensures the user has entered, what we consider to be a valid UK postcode:
ValidationExpression="^\s*([A-Z]{1,2}[0-9R][0-9A-Z]?\s*[0-9][ABD-HJLNP-UW-Z]{2})\s*$"
This works fine if the user enters their postcode using uppercase, but I'd like it to ignore case and am not sure how to incorporate that into the above expression?
I'd like it to ignore case
Activate the ignore case flag by adding this notation to your regex: i.
Your regex would like this one below:
ValidationExpression="/^\s*([A-Z]{1,2}[0-9R][0-9A-Z]?\s*[0-9][ABD-HJLNP-UW-Z]{2})\s*$/i"
The only simple solution is to put lowercase letters everywhere, i.e.: [0-9A-Za-z]
Other solutions are not always reliable.

how to force TextBox to only accept strings

Sorry for the Dummy Question , i know :( ,, but it's only the simple things that dont work with me :((
i have many text boxes and i want the user to only insert String and not Numeric numbers ,
how could i handle it in easy way ??
as it takes every thing and apply it to the database , or should i control it from the Database
PS. i have searched a lot but with no good answer
use [a-zA-Z]+ for ValidationExpression:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
ValidationExpression="[a-zA-Z]+"></asp:RegularExpressionValidator>
You could take a look at validation techniques for asp : http://msdn.microsoft.com/en-us/library/7kh55542.aspx
This provide a set of tools to check whether the input match what you expect.
You can do it easily in AJAX,just download it from here
first add a script manager to your page then add FilteredTextBoxExtender to the textbox and set it's properties as you wish.
A Regular Expression could be applied to the input
For the basics on RegEx : http://www.regular-expressions.info/tutorial.html
And also see
http://www.regular-expressions.info/dotnet.html
You can use regex to do that with jQuery.
In this example, I replace only digits.
You can adapt the regex to replace any set of characters with an empty string.

Validation expression for telephone number including hypens?

I am using ajax mask for entering telephone number and now I want to validate the telephone number too. but I don't know what will be the validation expression to use with it.I have tried some but all vain. So please help me as soon as possible.I want to validate the number like 999-999-9999. Thank You
try this one
\d{3}-\d{3}-\d{4}
^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$

ASP.NET Regular Expression Validator

I need a Regular Expression that can validate an exact 3 character(alpha only) code but also a blank field to set as the validation expression of a ASP.NET RegEx validator control.
I am currently using ^[a-zA-Z]{3}$
and this works out well to match the code but of course doesn't match a blank.
I have been looking at using something like this:
^(?:|)[a-zA-Z]{3}$
If your intention is to allow blank fields, then use the original pattern of ^[a-zA-Z]{3}$ since the RegularExpressionValidator doesn't validate blank fields. It will allow them.
However, if you want to prevent blank entries then you'll need to add a RequiredFieldValidator to validate the same control, in addition to the RegularExpressionValidator.
Have you tried using (^$)|(^[a-zA-Z]{3}$)?

Validation for TextBox For a User Form

In my User Registration Form, I want my user address text box to accpet alphanumeric as well as special character but should not contain only numeric or special character.
I am currently using regular expression validator ,what regular expression i can use.
Or Is there any different solution for that.
Regards
Here you go.. I have used it at one place, and works pretty well.. just provide your acceptable characters and you are good to go
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/FilteredTextBox/FilteredTextBox.aspx
You mean from your question that a string of alphabets is a must right ?

Resources