Js_ Regular Expression _ validation Chinese characters

Source: Internet
Author: User

Regular Expressions: The meaning of "^[\u4e00-\u9fa5]{0,}$", "/^[\u4e00-\u9fa5]{1,5}$/":

In JS, \uxxxx is the escape character, "XXXX" corresponds to the 16 Unicode encoding;

^ matches the start of a row. For example, the regular expression ^123 can match the beginning of the string "12345", but cannot match "012345";
[\u4e00-\u9fa5] refers to a match between these two Unicode encoding characters;
{0,} repeat 0 to infinity;
$ ends with it, as 123$ is only matched with 123 end. 1234 does not match.

That is, a string that matches any character that \u4e00-\u9fa5 between two characters (which can be more than 1 characters) and that there are no other characters before or after the string.

Typical applications:

1$(function(){2     //Verify Contacts3$ (' input[name= ' Contacts "]). Focus (function(){4$( This). Next (). Text (' only supports Chinese characters ');5}). blur (function(){6         varPattern =/^[\u4e00-\u9fa5]{1,5}$/;7         if(Pattern.test ($ ( This). Val ())) {//Use the native JS test () function to match the passed-in value and return a Boolean value. 8$( This). Removeclass (' Input_err ');9$( This). Next (). Text (' √ '). Removeclass (' Txt_err '). addclass (' Txt_correct ').);TenIstrue=true; One}Else{ A$( This). addclass (' Input_err '); -$( This). Next (). Text ("X"). Removeclass (' Txt_correct '). addclass (' Txt_err ').); -         } the     }); -  -     //Verify your phone number -$ (' input[name= ' Tel "]). Focus (function(){ +$( This). Next (). Text (' Landline, use-separate ')); -}). blur (function(){ +         varPattern =/^1\d{10}$|^ (0\d{2,3}-?| \ (0\d{2,3}\))? [1-9]\d{4,7} (-\d{1,8})? $/; A         if(Pattern.test ($ ( This). Val () )) { at$( This). Removeclass (' Input_err '); -$( This). Next (). Text (' √ '). Removeclass (' Txt_err '). addclass (' Txt_correct ').); -Istrue=true; -}Else{ -$( This). addclass (' Input_err '); -$( This). Next (). Text ("X"). Removeclass (' Txt_correct '). addclass (' Txt_err ').); inIstrue=false; -         } to     }); +})

Js_ Regular Expression _ validation Chinese characters

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.