Regular Expression Test

Regular Expression Test

by Nirvanachain

HTML

<form name="myForm">
    <input type="text" name="myText" id="testText" />
    <input type="submit" class="js-click" value="submit" />
</form>

JavaScript

function testRegEx (event) {
    event.preventDefault();
    // Regular Expression. Pattern must match lowercase, uppercase, and the special characters.
    var cond1 = /[a-z]/,
        cond2 = /[A-Z]/,
        cond3 = /[!@#\$%\^&\*]/;
    
    console.log('test fire');
    
    textValue = document.myForm.myText.value;
    console.log(textValue);
    if (!cond1.test(textValue) || !cond3.test(textValue) || !cond3.test(textValue)) {
        alert('Failure: the text value DOES NOT MATCH the Regular Expression')
    } else {
        alert('Success the text value MATCHES the Regular Expression');
    }
   

};

var button = document.querySelector('.js-click');

button.addEventListener('click', testRegEx);