JS uses regular expressions to determine the mailbox format

Source: Internet
Author: User

  

1 <HTML>2 <Head>3 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" />4 <title>Verify email is correct</title>5 <Scriptlanguage= "JavaScript">6 functionCheckemail (str) {7  //in JavaScript, regular expressions can only start and end with "/" and cannot use double quotation marks8 varExpression=/\w+ ([-+. '] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */; 9 varObjexp=NewRegExp (Expression);Ten if(Objexp.test (str)==true){ One     return true; A }Else{ -     return false; - } the } - functionCheck (myform) { -     if(Myform.email.value==""){ - Alert ("Please enter your email address!"); Myform.email.focus ();return; +     } -     if(!Checkemail (Myform.email.value)) { + Alert ("you entered the email address is not correct!"); Myform.email.focus ();return; A     } at myform.submit (); - } - </Script> - </Head> - <Body> - <formname= "Form1"Method= "POST"Action=""> in <Tablewidth= "100%"Height= "276"Border= "0"cellpadding= "0"cellspacing= "0"> -           <TR> to             <TDwidth= "16%"Height= "The "Align= "Center">Message Person:</TD> +             <TDwidth= "84%"> -               <inputname= "Author"type= "text"ID= "Author"size= "+"title= "message Person"></TD> the           </TR> *           <TR> $             <TDHeight= "$"Align= "Center">Email:</TD>Panax Notoginseng             <TD><inputname= "Email"type= "text"ID= "Email"size= " the"title= "Email address"> -                </TD> the           </TR> +           <TR> A             <TDHeight= " a"Align= "Center">&nbsp;</TD> the             <TD><inputname= "Submit"type= "button"class= "Btn_grey"value= "Save"OnClick= "Check (form1)"> +               &nbsp;&nbsp; -               <inputname= "Submit2"type= "Reset"class= "Btn_grey"value= "Reset">&nbsp;&nbsp;</TD> $           </TR> $         </Table> - </form>     - </Body> the </HTML>

Note: Regular expressions can only start and end with "/" and cannot use double quotes, so you should pay attention when you write the regular.

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.