Home >Java >javaTutorial >Regular verification cannot contain Chinese implementation methods [jQuery and java implementation]

Regular verification cannot contain Chinese implementation methods [jQuery and java implementation]

高洛峰
高洛峰Original
2017-01-22 14:35:261521browse

The example in this article describes the implementation method of regular verification that cannot contain Chinese. Share it with everyone for your reference, the details are as follows:

jQuery uses regular verification to not contain Chinese

var myReg = /^[a-zA-Z0-9_]{0,}$/;
if (!myReg.test(input.val())) {
  $.validation.tip(false, input, "用户名不能含有中文或特殊字符");
  return;
}

Java verification string does not contain Chinese

if (nickname.getBytes().length != nickname.length()) {
  errors.add("用户名不能含有中文");
}

I hope this article will be helpful for everyone to learn regular expressions.

For more implementation methods that cannot contain Chinese for regular verification [jQuery and java implementation], please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn