Http://www.asp888.net bean curd technology station
We have discussed the use of regular expressions in asp.
Use C # In asp.net to experience how regular expressions in asp + are used.
First, we use the Regex class overload constructor to create an object that we want to judge using a regular expression. The Code is as follows:
Regex r = new Regex ("^ ([a-z0-9 _] | \-| \.) + @ ([a-z0-9 _] | \-) + \.) + [a-z] {2, 4} $ "); // This is a legal mail address.
This regular expression is a regular expression used in the previous article to determine whether the Email address is valid.
See the document asp using regular expressions.
Note some minor differences here. in C # language, "" is given special escape meanings, such as "", to be able
Correct Understanding of "", we must use the "\" symbol to express a "" symbol
Next, let's take a look at our complete code:
<Script language = "c #" runat = server>
Protected void Page_Load (Object Src, EventArgs E ){
If (judgeMail ("webmaster@asp888.net "))
Showmsg. Text = "valid address ";
}
Bool judgeMail (String strMail ){
// Regex r = new Regex ("^ [a-zA-Z] \ w {3, 15} $"); // This is a password issue.
Regex r = new Regex ("^ ([a-z0-9 _] | \-| \.) + @ ([a-z0-9 _] | \-) + \.) + [a-z] {2, 4} $ "); // This is a legal mail address.
Return r. IsMatch (strMail );
}
</Script>
<Asp: Label id = showmsg runat = server Text = "Invalid Address"/>