PrepAway - Latest Free Exam Questions & Answers

Which expression should you insert into each function?

DRAG DROP
You are validating user input by using JavaScript and regular expressions.
A group of predefined regular expressions will validate two input fields:
An email address in a function named validateEmail (for example, firstname@contoso.com)
A nine-digit number that allows optional hyphens after the second and fifth character in a
function named validateSSN(for example, 555555555 or 555-55-5555)
You need to use the correct expression to validate the input.
Which expression should you insert into each function? (To answer, drag the appropriate
regular expression statement to the correct location. Each regular expression statement may
be used once, more than once, or not at all. You may need to drag the split bar between
panes or scroll to view content.)

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:

10 Comments on “Which expression should you insert into each function?

  1. Will says:

    The correct RegExp for SSN is:

    var ssnPattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;

    Explanation:
    ^: Begins with
    [0-9]{3}: 3 characters between 0 to 9.
    \-?: Zero or One Dash character
    [0-9]{2}: 2 characters between 0 to 9.
    \-?: Zero or One Dash character
    [0-9]{4}: 4 characters between 0 to 9.
    $: Ends with

    —————————————————————–
    Simple sample web page for testing a regex
    —————————————————————–

    REGEX TEST

    .Success {color: Green;}
    .Failed {color: Red;}

    Enter Text:

    var btnRegex = document.getElementById(“btnRegex”);
    btnRegex.onclick = function () {

    var txtboxTest = document.getElementById(“txtTest”);
    var strTest = txtboxTest.value;
    var divResponse = document.getElementById(“divResponse”);

    var re = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;
    if (strTest.match(re)) {
    divResponse.innerHTML = “Match!”;
    divResponse.className = “Success”;
    }
    else {

    divResponse.innerHTML = “Not a match!”;
    divResponse.className = “Failed”;
    }
    }




    0



    0

Leave a Reply