1 Problem description
In a dialog box, the user enters a set of strings that need to satisfy a length of 1 to 6 and need to be made up of 0-9,a-z, or A-Z, and other use cases are illegal.
2 Equivalence class Partitioning
|
Valid equivalence classes |
Number |
Invalid equivalence class |
Number |
Number of characters |
1-6 |
1 |
0 |
4 |
|
|
2 |
7 |
5 |
Character type |
A-z,a-z,0-9 |
3 |
Other characters |
6 |
|
|
|
Punctuation |
7 |
|
|
|
Control characters |
8 |
3 Code and dialog box design
Use regular expressions to determine.
Code:
<HTML><Head><Scripttype= "Text/javascript">functionfoo () {varStr=document.getElementById (str'). Value; var st=/^[a-za-z0-9_]+$/; if (!st.test (str) | | str.length<1| | str.length>6) {Window.alert ("error"); } else{Window.alert ("succeed"); }}}</script>
4 test Cases and results:
Case |
overriding equivalence classes |
Results |
04t6 |
1,3 |
Success |
04,5 |
1,3,7 |
Failed |
Derterr |
5 |
Failed |
sdrt5& |
1,3,8 |
Failed |
Ha ha |
1,6 |
Failed |
Erz\ |
1,3,6 |
Failed |
Null value |
4 |
Failed |
Results
Validation of test cases with JavaScript