Numbers Only Please

[Total: 0    Average: 0/5]

This script validates form input to be numbers.

Body Code:

<form>
Enter 9 numbers: <input type=text name=numbers>
<BR>
<input type=button onclick=verify(this.form) value="verify">
</form>
<script>
function verify(_f)
{
  var _x=_f.numbers.value;

  var _exp = new RegExp(/^d+$/);
  var _test=_exp.test(_x);

  if(_x.length!=9)alert("length not correct");
  else if(!_test)alert("non digits found");
  else alert("this value is okay.");
}
</script>

Times Viewed: 3

Leave a Reply

Your email address will not be published. Required fields are marked *