Regular expression validation for mailboxes and Passwords (C #)

Source: Internet
Author: User

Just contact regular expression, found that its function unexpectedly so “ very good very strong &rdquo, and then use C # to write a mailbox verification, little brother dishes, if there are deficiencies please point out, but also want to contact the regular expression of the brothers and sisters help.

Here is the Code section:

Using System;

Using System.Collections.Generic;

Using System.ComponentModel;

Using System.Data;

Using System.Drawing;

Using System.Text;

Using System.Windows.Forms;



Using System.Text.RegularExpressions; namespace Regulatortest {public partial class Form1:form {public Form1 () {I

        Nitializecomponent (); } private void btnTest_Click (object sender, EventArgs e) {//verify e-mail Format St

            Ring Regexemail = "//w{1,}@//w{1,}//.//w{1,}"; System.Text.RegularExpressions.RegexOptions options = ( System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) |

            System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            System.Text.RegularExpressions.Regex regemail = new System.Text.RegularExpressions.Regex (regexemail, Options);

 string email = Txtemail.text;           

            if (regemail.ismatch (email))//email fill in the regular expression "//w{1,}@//w{1,}//.//w{1,}" { MessageBox.Show ("Conforming to regular expression: +regemail.tostring () +"/N mailbox completed successfully.

            "); else {MessageBox.Show ("does not conform to regular expression: +regemail.tostring () +"/N mailbox format is not correct.)

                ");

            Return

            //Verify that the password is made up of no less than 6-bit alphanumeric underline special symbols. String regexpwd = "^. {6,15}___fckpd___0quot;;/ /Limit the beginning, must start from the first match, limit the end, the total number of digits must not exceed 15 digits, otherwise even greater than 15 bits can still verify through System.Text.RegularExpressions.Regex regpwd = new System.te Xt.

            Regularexpressions.regex (regexpwd, Options);

            string pwd = Txtpwd.text; if (Regpwd.ismatch (pwd)) {MessageBox.Show ("conforming to regular expression: +regpwd.tostring () +"//n Password Authentication passed.

            "); else {MessageBox.Show ("does not conform to regular expression: +regpwd.tostring () +"//n Password Authentication failed.) The password should be made up of no less than 6-bit alphanumeric underline special symbols.

                ");

            Return }} PRivate void Form1_Load (object sender, EventArgs e) {}} 

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.