problem Description : Allow 1 to 6 English characters or numbers, press OK to end
valid equivalence classes : Lengths: 1 to 6
Character: a-z,a-z,0-9
invalid equivalence class : Length: 0,7
Characters: English/numeric characters, control characters, punctuation
Can be drawn:
Valid equivalence classes |
Invalid equivalence class |
Length:1-6 |
Length:. -0&&7-.. |
Char:a-z&&a-z&&0-9 |
Char:others |
The test cases and results used are:
Test Cases |
Test results |
0 |
Effective |
A |
Effective |
Z |
Effective |
9 |
Effective |
AA90 |
Effective |
Ababab |
Effective |
9a2b7c |
Effective |
Mmmmmm |
Effective |
bbbbbb |
Effective |
12 |
Effective |
123 |
Effective |
1234 |
Effective |
12345 |
Effective |
123456 |
Effective |
1234567 |
Invalid |
Abcdefg |
Invalid |
Akbugg |
Effective |
、 |
Invalid |
**** |
Invalid |
Kghggggg |
Invalid |
1k2m3 |
Effective |
|
Invalid |
The key code for the programming test implementation is:
12 34<script type= "Text/javascript" >5 functionequaltest () {6 varName = document.getElementById (' name '). Value;7 if(Name = =NULL)8 {9Window.alert ("User name cannot be empty");Ten } One Else A { - varnlen=name.length; -reg=/^[a-za-z0-9_]+$/; the - if(nlen<1| | Nlen>6) - { -Window.alert ("illegal") + } - Else if(!reg.test (name)) + { AWindow.alert ("illegal"); at } - Else return; - } - } -</script> - in -<body> to<input type= "text" id= "name"/><br/> +<input type= "button" onclick= "Equaltest ()" value= "OK"/> -</body> the *PS: In regular expressions, if a character is given directly, it is precisely matched. You can match a number to match \d
\w
a letter or a number.
To make a more accurate match, you can use a []
representation range, such as:
[0-9a-zA-Z\_]
Can match a number, letter, or underscore;
[0-9a-zA-Z\_]+
Can match a string of at least one number, letter, or underscore, for example, and ‘a100‘
‘0_Z‘
‘Py3000‘
so on;
[a-zA-Z\_][0-9a-zA-Z\_]*
It can be matched by a letter or underscore, followed by a string consisting of a number, letter, or underscore, which is a valid Python variable;
[a-zA-Z\_][0-9a-zA-Z\_]{0, 19}
More precisely limit the length of a variable to 1-20 characters (1 characters before + 19 characters later).
Validity verification of user name input in--web development of equivalence class test