Repeat the regular expression (this is an application on asp.net)

Source: Internet
Author: User

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"/>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.