validation
-
hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that
-
hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character. something like:
string text = TextBox1.Text;
string[] split = text.split('@');
if(split.length == 1)//only one '@' character
{
if(split[1].Contains('.'))
//Could be a valid email
}
//else is not a valid email address -
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character. something like:
string text = TextBox1.Text;
string[] split = text.split('@');
if(split.length == 1)//only one '@' character
{
if(split[1].Contains('.'))
//Could be a valid email
}
//else is not a valid email addressmusefan wrote:
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.
Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that
abu rakan wrote:
hi men
There are women on this site, too. There's a control built in for validating text, or, as someone said, you can use regex.
Christian Graus Driven to the arms of OSX by Vista.
-
musefan wrote:
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.
Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
abu rakan wrote:
hi men
There are women on this site, too. There's a control built in for validating text, or, as someone said, you can use regex.
Christian Graus Driven to the arms of OSX by Vista.
-
I am soooooo sorry "Christian Graus" about hi men about my problem actually i don't understand you or may be you don't understand me!!!!
This is a javascript email validator. This validator can be customized to allow any domain name.
*/ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminycricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse -
musefan wrote:
well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.
Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
<asp:TextBox ID="tbEmail" runat="server" ValidationGroup="Register" />
<asp:RegularExpressionValidator ForeColor="Red" ValidationGroup="Register" ControlToValidate="tbEmail" ErrorMessage="Email Address is not valid." ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" EnableClientScript="true" ID="RegularExpressionValidator1" runat="server" Display="Dynamic" />
Or you could create a custom validator that will do the validation for you and set your page IsValid property to true or false depending whether valid or not.