Java Script Validation for Text Boxes
function NumberhyphenOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45) || (AsciiValue==47))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues, '/', '-' Only");
}
}
function NumberCharandHypehn()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122 ) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45) || (AsciiValue==47) || (AsciiValue==46) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues, '/', '-' Only");
}
}
function NumberOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues Only");
}
}
function PhoneNumberOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues Only");
}
}
function DecimalOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57 ) || (AsciiValue==8 || AsciiValue==127) || AsciiValue==46)
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter DecimalValues Only");
}
}
function CharOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122 ))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Charcters Only");
}
}
function CharbarOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue==97 || AsciiValue==47 || AsciiValue==45) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==32) || (AsciiValue==44) || (AsciiValue==46) )
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphanumeric,- and / Only");
}
}
function CharnumOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphanumeric Only");
}
}
function Names()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue==46) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphabets, '.' and Space Only");
}
}
function Sonof()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue==46) || (AsciiValue==47) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphabets, '.', '/' and Space Only");
}
}
function NumberhyphenOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45) || (AsciiValue==47))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues, '/', '-' Only");
}
}
function NumberCharandHypehn()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122 ) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45) || (AsciiValue==47) || (AsciiValue==46) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues, '/', '-' Only");
}
}
function NumberOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues Only");
}
}
function PhoneNumberOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==45))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter NumericValues Only");
}
}
function DecimalOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=48 && AsciiValue<=57 ) || (AsciiValue==8 || AsciiValue==127) || AsciiValue==46)
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter DecimalValues Only");
}
}
function CharOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122 ))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Charcters Only");
}
}
function CharbarOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue==97 || AsciiValue==47 || AsciiValue==45) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127) || (AsciiValue==32) || (AsciiValue==44) || (AsciiValue==46) )
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphanumeric,- and / Only");
}
}
function CharnumOnly()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphanumeric Only");
}
}
function Names()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue==46) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphabets, '.' and Space Only");
}
}
function Sonof()
{
var AsciiValue=event.keyCode
if((AsciiValue>=65 && AsciiValue<=90) || (AsciiValue>=97 && AsciiValue<=122) || (AsciiValue==46) || (AsciiValue==47) || (AsciiValue==32))
event.returnValue=true;
else
{
event.returnValue=false;
alert("Enter Alphabets, '.', '/' and Space Only");
}
}
use below code firefrox
ReplyDeletefunction NumberOnly(evt)
{
var AsciiValue = (evt.which) ? evt.which : event.keyCode
// alert(AsciiValue);
//var AsciiValue=event.charCode ? event.charCode : event.keyCode;
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
AsciiValue.returnValue=true;
else
{
alert("Enter NumericValues Only"+AsciiValue);
AsciiValue.returnValue=false;
}
}
Use Below code to worked in Firefox,Chrome & IE
ReplyDeleteJavascript Function :
function NumberOnly(evt)
{
var AsciiValue = (evt.which) ? evt.which : event.keyCode
// evt.which fires in Firefox & event.keyCode works in chrome & IE
if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
{
evt.returnValue=true;
}
else
{
alert("Enter NumericValues Only");
evt.returnValue=false;
}
}
Execution Step :
on Input Control add the Event as onkeypress='functionname(event)'
Event means – Which Event Fires