Regular expressions Verify that the input user name format is correct (ii)

Source: Internet
Author: User

A description of the problem

3 EditBox, each allowed to enter 1 to 6 English characters or numbers, press OK to enter the end

(Returns the wrong information by entering a string)

Two effective equivalence classes and invalid equivalence class partitioning:

Valid equivalence classes Invalid equivalence class
LENGTH=[1-6] Length=0 or Length>6
CHAR=[A-ZA-Z0-9] Other chars
Correctnum=3 Correctnum<3

Three test Cases

Number Input Expected output
1

String 1 = "123"

String 2 = "Thomas"

String 3 = "Aa234"
Correct
2

String 1 = ""

String 2 = "Arcane"

String 3 = "Arcaneblast"
Invalid Input
3

String 1 = "695_SD"

String 2 = "Mage"

String 3 = "Ac"
Invalid Input
4

String 1 = "Fire"

String 2 = "233"

String 3 = "I"
Correct
5

String 1 = "Frost"

String 2 = "Frost_orb"

String 3 = "23"
Invalid Input
6

String 1 = "Arcanemissle"

String 2 = "Thomas"

String 3 = "Aa234"
Invalid Input
7

String 1 = "123"

String 2 = "Txsds"

String 3 = "sdder2223"
Invalid Input
8

String 1 = "12"

String 2 = "th"

String 3 = "Aa234"
Correct
9

String 1 = ""

String 2 = "Pyroblast"

String 3 = "334"
Invalid Input
10

String 1 = "123"

String 2 = "Thomas"

String 3 = "Aa234"
Correct

Four Code implementations

functionTest () {varInput1=document.getelementbyid (' input1 '). Value;varInput2=document.getelementbyid (' Input2 '). Value;varInput3=document.getelementbyid (' Input3 '). Value;if(input1== "") {Window.alert ("Invalid Input");}Else{varn=Input1.length;reg=/^[a-za-z0-9_]+$/; if(n<1| | N>6) {Window.alert ("Invalid Input")}Else if(!reg.test (INPUT1)) {Window.alert ("Invalid Input");} }}if(input2== "") {Window.alert ("Invalid Input");}Else{varn=Input2.length;reg=/^[a-za-z0-9_]+$/; if(n<1| | N>6) {Window.alert ("Invalid Input")}Else if(!reg.test (INPUT2)) {Window.alert ("Invalid Input");} }}if(input3== "") {Window.alert ("Invalid Input");}Else{varn=Input3.length;reg=/^[a-za-z0-9_]+$/; if(n<1| | N>6) {Window.alert ("Invalid Input")}Else if(!reg.test (INPUT3)) {Window.alert ("Invalid Input");} }}</script>

Regular expressions Verify that the input user name format is correct (ii)

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.