-1

What's the proper syntax to add css into the below script in the if condition?

function validateEmail(emailField){
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if (reg.test(emailField.value) == false) 
        {
            alert('Invalid Email Address');
            return false;
        }

        return true;
dan
  • 593
  • 6
  • 19

2 Answers2

2

Create a span with an id

<span id="emailMsg">Wrong Email format</span>

and you can do this in your script

function validateEmail(emailField){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (reg.test(emailField.value) == false) 
    {
        document.getElementById('emailMsg').style.color = '#FF0000';
        return false;
    }

    return true;

Note that I didn't validate your regex. I simply added javascript that changes color.

Saehun Sean Oh
  • 2,103
  • 1
  • 21
  • 41
-1

Using JQuery, you can easily modify any element using .css(), in this case by specifying

$(emailField).css('color', '#F00');
user0934
  • 126
  • 9