Validation of test cases with JavaScript

Source: Internet
Author: User
Tags control characters

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.