JS Regular expression Matching mailbox

Source: Internet
Author: User
Tags regular expression

For example, ' zo+ ' can match "Zo" and "Zoo", but cannot match "Z". + is equivalent to {1,}. {n,m} m and n are non-negative integers, where n <= m. Matches n times at least and matches up to M times. For example, "o{1,3}" will match the first three o in "Fooooood". ' o{0,1} ' is equivalent to ' o '. Notice that there is no space between the comma and the two number.


Javascript Mailbox Validation Regular Expression example

The code is as follows Copy Code


Myreg =/^ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+. [A-za-z] {2,4}$/; Javascript

Example of a mailbox validation regular expression

  code is as follows copy code


< Script type= "Text/javascript"
Function Isemail (val) {
           var myreg =/^ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+. [A-za-z] {2,4}$/;
 
          if (!myreg.test (val))
           return ' is not a mailbox ';
          return ' is mailbox ';
};
Alert (isemail (' i@fufuok.com '));
</script>

Two. Explain the relevant meaning
     1. /^$/This is a generic format.
         ^ matches the start position of the input string; $ matches the end position of the input string
     2. Inside, enter the functionality you want to implement.
        * matches the preceding subexpression 0 or more times;
       + Matches the preceding subexpression one or more times;
       Matches the preceding subexpression 0 times or once;
       d  matches a numeric character, equivalent to [0-9]

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.