0

I am trying to validate email to access alphanumeric characters

<script type = "text/javascript">
function checkField(email)
{
if (/[^0-9a-bA-B\s]/gi.test(email.value))
{
alert ("Only alphanumeric characters and spaces are valid in 
this field");
email.value = "";
email.focus();
return false;
}
}
</script>

it must contain alphabets and numerics ex:"test123@gmail.com","admin890@gmail.com" , "abc456@gmail.com" .. how can rewrite this code.?? enter image description here

StepUp
  • 36,391
  • 15
  • 88
  • 148
Twinxz
  • 303
  • 5
  • 16
  • i want to validate email id – Twinxz May 05 '16 at 11:04
  • regular_exp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; To validate email use this regular exp – Pardeep Poria May 05 '16 at 11:05

1 Answers1

0

I am matching two reg exp as i am not sure how to combine them but it works only for alphanumeric

<form method="post" name="client_form" id="client_form"> <input name="email" id="email" type="text" value="" class="formq" tabindex="1" style="width:200px" autocomplete="off" onblur="checkField(this.value)"/>
</form>
<script>
function checkField(email){ 
console.log(email);
      var reg_exp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
      var chk = reg_exp.test(email);
      var checkalphanumeric = email.split("@");
      var alphanumeric_chk = /^(\d+[a-z]|[a-z]+\d)[a-z\d]*$/i;
      var check2 = alphanumeric_chk.test(checkalphanumeric[0]);
      console.log(check2);
      if(chk && check2){
          alert("valid");
      } else { 
          alert("Only alphanumeric characters and spaces are valid in this field"); 
      }
}
</script>

Here is what happens on 123@gmail.com enter image description here

Pardeep Poria
  • 1,049
  • 1
  • 7
  • 12