Regular Expression to verify string Composition

Source: Internet
Author: User

Regular Expression to verify string Composition

<Script type = "text/javascript">
Function check_str (){
Var str = document. getElementById ("str"). value;
Var check_letters =/^ [a-zA-Z] + $/. test (str); // The Judgment string is composed of letters.
Var check_numbers =/^ [0-9] + $/. test (str); // The Judgment string is composed of digits.
Var check_l_n =/^ [a-zA-Z0-9] + $/. test (str); // judge a string consisting of digits or letters
Var check_chn =/^ [\ u4E00-\ u9FA5] + $/. test (str) // The Judgment string is composed of Chinese characters.

Var result = "Pure letter:" + check_letters + "\ n pure number:" + check_numbers + "\ n letter or number:" + check_l_n + "\ n pure Chinese: "+ check_chn;
Alert (result );

If (/[^ \ x00-\ xff]/g. test (str )){
Alert ("including Chinese ")
} Else {
Alert ("not including Chinese ")
}
If (check_letters ){
Alert ("only letters ");
} Else if (check_numbers ){
Alert ("Pure digit ");
} Else if (check_l_n ){
Alert ("letters or numbers ");
} Else if (check_chn ){
Alert ("Chinese only ")
} Else {
Alert ("hybrid ");
}

}
</Script>

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.