Tuesday, September 1, 2009

How to check the field is Numeric or Not ?

The small example shows the validation for the field is numeric or not:

<script type='text/javascript'>

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
<form>
Enter Phone No : <input type='text' id='numbers'/>
<input type='button'
onclick="
isNumeric(document.getElementById('numbers'), 'Numbers Only Please')"
value='Check Field' />
</form>

No comments:

Post a Comment

Please comment on this