Javascript regularly matches Chinese characters Numbers letters and underscores

  • 2020-03-30 02:36:29
  • OfStack

Javascript regularization detection only contains Chinese characters, Numbers, letters, and underscores, not the beginning and end of the underscore

Encountered a user name detection problem, looked up, summarized the example as follows:


var reg = /^(?!_)(?!.*?_$)[a-zA-Z0-9_u4e00-u9fa5]+$/;
if (!reg.test( The actual value of the string )) {
    alert(' Please enter the 5-24 Bit characters: support Chinese, English, numerals," _ , Chinese is recommended ');
}


Related articles: