Reference:
https://blog.csdn.net/qq_35129893/article/details/80695811
https://blog.csdn.net/youcijibi/article/details/80902622
1. Judgment of Chinese and English names: Restricted conditions:
Chinese name length ≥ 2 characters, ≤ 200 characters. Can contain Chinese characters, "●" (I don't know how to type this stuff...). The character spacing does not support spaces, special characters other than "●", and numbers are not allowed.
The length of the English name is ≥ 1 character and ≤ 200 characters. Can contain letters, numbers, brackets, a space between characters, ".", "●", "-"
The following two lines are different from the ● in the Chinese name
^(?:[\u4e00-\u9fa5]+)(?:●[\u4e00-\u9fa5]+)*$|^[a-zA-Z0-9]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$
/^(?:[\u4e00-\u9fa5]+)(?:·[\u4e00-\u9fa5]+)*$|^[a-zA-Z0-9]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$/
Complete demo:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>input</title>
</head>
<body>
<input type="text" class="name">
<script src="js/jquery-1.11.0.min.js"></script>
<script>
var regName = /^(?:[\u4e00-\u9fa5]+)(?:·[\u4e00-\u9fa5]+)*$|^[a-zA-Z0-9]+\s?[\.·\-()a-zA-Z]*[a-zA-Z]+$/;
$("input").blur(function () {
var name = $(".name").val();
if(!regName.test(name)){
alert("×")
}else{
alert("√")
}
})
</script>
</body>
</html>
2. Chinese name judgment (2-4 characters)
var regName = /^[\u4E00-\u9FA5]{2,4}$/;