Form validation of numeric characters

Jimmy Wales Reply 15:20
You need to test for the negation of the Regular Expressions because you want the validation to alert upon failure,

(is_valid = !/^[0-9]+$/.test(x))
Example :-

<form action="" method="POST" name="cdp_form" id="cdp_form">
<input type="text" id="phone_number" name="phone_number" placeholder="Enter your phone number" maxlength="10" onkeyup="validateForm()">
<button type="submit" name="SEND" class="btn btn-brown">Send</button>
</form>
<?php echo $successmsg; ?>
<script>
//form validation
function validateForm()
{
var x=document.forms["cdp_form"]["phone_number"].value
if (x==null || x=="")
  {
  alert("Phone number  field must be filled in");
  cdp_form.phone_number.focus();
  return false;
  }
else if (is_valid = !/^[0-9]+$/.test(x))
    {
    alert("Phone number field must have numeric characters");
    cdp_form.phone_number.focus();
    return false;
  }
}
</script>

Related Posts

validation 2047222783280770909
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us