Javascript validations for Numeric data and Integers

These are some useful javascript functions you can use for validation in html.
You can use it

onkeyup,
onchange,
onsubmit,
onclick,
….

If only numbers need to be accepted

function allnumeric()
{
mobileNo = document.getElementById(“mobileNo”);
var numbers = /^[0-9]+$/;
if(mobileNo.value.match(numbers))
{
alert(‘Your have given a valid phone number in digits. Continue.. ‘);
return true;
}
else
{
alert(‘Please input numeric characters only’);
return false;
}
}

If numbers need not be accepted

function nonumeric()
{
username = document.getElementById(“username”);
var numbers = /^[0-9]+$/;
if(!username.value.match(numbers))
{
alert(‘Username can’t have numbers in it. Please remove it…’);
return true;
}
else
{
alert(‘Please input numeric characters only’);
return false;
}
}

If a negative or positive integer need to be checked


function integercheck()
{
integer = document.getElementById(“integer”);
var integerpattern = /^[-+]?[0-9]+$/;
if(integer.value.match(integerpattern))
{
alert(‘You haven’t given an integer. Please verify..’);
return true;
}
}


VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Related Posts Plugin for WordPress, Blogger...

Comments

Total Views :417
avatar

About Moviefreak