Saturday, September 11, 2010

Validation

Name Validator
=============
"input type="text" name="city_name" id="city_name" title="City Name" class="txtbox" onkeypress="return valPersonName(event);" onblur="Trim_Spaces(this.id);"
=============
function valPersonName(evt)
{
var charCode;
charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode >= 97 && charCode <= 122 || charCode >= 65 && charCode <= 90 || charCode==32 || charCode==46 || charCode==8)
{
return true ;
}
else
{
return false;
}
}
PhoneValidator
=============
"input name="txtPhoneNo" type="text" id="txtPhoneNo" title="Phone No." class="txtbox" onkeypress="return valPhone(event);" onblur="Trim_Spaces(this.id);"
===========
function valPhone(evt)
{
var charCode;
charCode = (evt.which) ? evt.which : event.keyCode;getAttention
if (charCode == 40 || charCode == 41 || charCode == 43 || charCode == 44 || charCode == 45 || charCode >= 48 && charCode <= 57 || charCode == 32 || charCode==8)
{
return true;
}
else
{
return false ;
}
}
====================================
Address and Long string like Interest and all
====================================
"textarea name="txtmessage" id="txtmessage" cols="29" rows="4" class="txtbox" style="height: 50px;" title="Message" onkeypress="return valSpecialset(event);" onblur="Trim_Spaces(this.id);"
"/textarea"
==================================

function valSpecialset(evt)
{
var charCode;
charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode >= 97 && charCode <= 122 || charCode >= 65 && charCode <= 90 || charCode >= 48 && charCode <= 57 || charCode==32 || charCode==36 || charCode==33 || charCode==42 || charCode==35 || charCode==64 || charCode==46 || charCode==8)
{
return true ;
}
else
{
return false ;
}
}
====================================
Email Validation
====================================

if(document.getElementById('txtEmailAddress').value!='')
{
var id = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.getElementById('txtEmailAddress').value;
if(id.test(address) == false)
{
alert('Invalid Email Address');
document.getElementById('txtEmailAddress').focus();
return false;
}
}

No comments:

Post a Comment