Javascript/JS restrict the user name from entering only letters and underscores
Function checkreg (){
VaR MSG = "sorry, input error/N ";
VaR regform = Document. All. reg;
VaR username = regform. Username;
VaR password1 = regform. password1;
VaR password2 = regform. password2;
VaR usern =/^ [a-zA-Z0-9 _] {1,} $ /;
// Alert (username. value );
If (! Username. value. Match (usern )){
MSG + = "the user name can only consist of letters, numbers, and underscores (_)/n ";
Alert (MSG );
Username. value = '';
Username. Focus ();
Return false;
}
If (password1.value! = Password2.value)
{
MSG + = 'inconsistent passwords entered twice ';
Alert (MSG );
Password1.value = '';
Password2.value = '';
Password1.focus ();
Return false;
}
Return true;
}
1. Only numbers are allowed.
<Input name = "username" type = "text" onkeyup = "value = This. value. Replace (// D +/g,'') ">
2. Only English letters, numbers, and underscores (_) are allowed)
<Input name = "username" type = "text" style = "ime-mode: Disabled">
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W/. //]/ig,'') ">
3. Only English letters, numbers, and = @ # are allowed @#
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W = @ #] | _/ig,'') ">
4. Only Chinese characters are allowed
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/u4e00-/u9fa5]/g,'') ">
1. Only numbers are allowed.
<Input name = "username" type = "text" onkeyup = "value = This. value. Replace (// D +/g,'') ">
2. Only English letters, numbers, and underscores (_) are allowed)
<Input name = "username" type = "text" style = "ime-mode: Disabled">
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W/. //]/ig,'') ">
3. Only English letters, numbers, and = @ # are allowed @#
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/W = @ #] | _/ig,'') ">
4. Only Chinese characters are allowed
<Input name = "username" type = "text" onkeyup = "value = value. Replace (/[^/u4e00-/u9fa5]/g,'') ">
Only numbers are allowed: "^ [0-9] * $ ".
Only n digits can be entered: "^/d {n} $ ".
You can only enter at least N digits: "^/d {n,} $ ".
Only M ~ can be input ~ N-digit :. "^/D {m, n} $"
Only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $ ".
Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $ ".
Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $ ".
Only a non-zero positive integer can be entered: "^/+? [1-9] [0-9] * $ ".
Only a non-zero negative integer can be entered: "^/-[1-9] [] 0-9" * $.
Only 3 characters can be entered: "^. {3} $ ".
You can only enter a string consisting of 26 English letters: "^ [A-Za-Z] + $ ".
You can only enter a string consisting of 26 uppercase letters: "^ [A-Z] + $ ".
You can only enter a string consisting of 26 lower-case English letters: "^ [A-Z] + $ ".
You can only enter a string consisting of a number and 26 English letters: "^ [A-Za-z0-9] + $ ".
You can only enter a string consisting of digits, 26 English letters, or underscores: "^/W + $ ".
Verify the User Password: "^ [A-Za-Z]/W {5, 17} $" the correct format is: start with a letter, length is 6 ~ It can only contain characters, numbers, and underscores.
Check whether ^ % & ',; =? $/"And other characters:" [^ % & ',; =? $/X22] + ".
Only Chinese characters can be entered: "^ [/u4e00-/u9fa5] {0,} $"