0

In my application i want to validate an email text filed on keypress ,but how to do that i have used validation on keypress for numbers .Like i am posting what i have done

$("#start-date").keypress(function (e) {
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
       $(".errmsg").html("Digits Only").show().fadeOut(3000);
               return false;
    }
   });


<input id="start-date" type="text" name="start-date"><span class="errmsg"></span>

.errmsg {
color: red;
font-weight: bold;
}

Upper code is working properly.

but i want to validate my email field like it

<aui:input inlineField="true" label="" name="interviewCC" id="interviewCC" size="45" value=""></aui:input>

This field i want to validate with email validation ,how to do that,please somebody help ,Thank in advance

lucifer
  • 2,297
  • 18
  • 58
  • 100

1 Answers1

0

Try this :-

    $('#youremailfield').on('keypress', function() {
    var re = /([A-Z0-9a-z_-][^@])+?@[^$#<>?]+?\.[\w]{2,4}/.test(this.value);
    if(!re) {
     $(".errmsg").html("Wrong Email").show().fadeOut(3000);
   } else {
     $(".errmsg").hide();
  }
 });
Naveen Chandra Tiwari
  • 5,055
  • 3
  • 20
  • 26