::::::
Validations::::::
--------------------------------ONLY
CHARECTERS---------------------ONLY CHARECTERS
function ValidateAlpha1(evt) {
var keyCode = (evt.which) ? evt.which
: event.keyCode
if ((keyCode < 65 || keyCode >
90) && (keyCode < 97 || keyCode > 123) && (keyCode != 32)
|| ((document.getElementById("<%=TextBox5.ClientID%>").value ==
"") && (keyCode == 32))) {
alert("Enter only
Characters");
return false;
}
}
---------------------------------ONLY
NUMBERS--------------------------------------
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which
: event.keyCode
if (charCode > 31 &&
charCode != 45 && charCode != 40 && charCode != 41 &&
(charCode < 48 || charCode > 57)) {
alert("Enter
Numerics Only");
return false;
}
}
---------------------------------------------ALPHANUMERIC--------------------------ALPHANUMERIC
function alphanumeric_only(e) {
var keycode;
if (window.event)
keycode =
window.event.keyCode;
else if (event)
keycode = event.keyCode;
else if (e)
keycode = e.which;
else
return true;
if ((keycode == 32) || (keycode >=
47 && keycode <= 57) || (keycode >= 65 && keycode <=
90) || (keycode >= 97 && keycode <= 122)) {
return true;
}
else {
return false;
}
return true;
--------------------------------------DROP
DOWNLIST-----------------------------------------
Validation for Dropdownlist::::::
function validate() {
if
(document.getElementById('<%=DropDownList1.ClientID%>').selectedIndex ==
0) {
alert("Please select Class");
return
false;
}
}
In Button Click:OnClientClick=" return validate()"
--------------------------------------DATE WITHOUT
AJAX---------------------------------------
function checkDt(fld) {
var mo, day, yr;
var entry = fld.value;
var reLong =
/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
var reShort =
/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
var valid =
(reLong.test(entry)) || (reShort.test(entry));
if (valid) {
var
delimChar = (entry.indexOf("/") != -1) ? "/" :
"-";
var delim1
= entry.indexOf(delimChar);
var delim2
= entry.lastIndexOf(delimChar);
mo =
parseInt(entry.substring(0, delim1), 10);
day =
parseInt(entry.substring(delim1 + 1, delim2), 10);
yr =
parseInt(entry.substring(delim2 + 1), 10);
// handle
two-digit year
if (yr
< 100) {
var today = new Date();
// get current century floor (e.g., 2000)
var currCent = parseInt(today.getFullYear() / 100) * 100;
// two digits up to this year + 15 expands to current century
var threshold = (today.getFullYear() + 15) - currCent;
if (yr > threshold) {
yr += currCent - 100;
} else {
yr += currCent;
}
}
var
testDate = new Date(yr, mo - 1, day);
if
(testDate.getDate() == day) {
if (testDate.getMonth() + 1 == mo) {
if (testDate.getFullYear() == yr) {
// fill field with database-friendly format
fld.value = mo + "/" + day +
"/" + yr;
return true;
} else {
alert("Check the year entry.");
}
} else {
alert("Check the month entry.");
}
} else {
alert("Check the date entry.");
}
} else {
alert("Invalid date
format. Enter as mm/dd/yyyy.");
}
entry.focus();
return false;
__________________________________________Mobile number starting
with 7,8,9____________________________
Validation for Mobile number starting with 7,8,9::::
function validateInput13() {
var txtCode =
document.getElementById("<%=TextBox25.ClientID%>");
var filter =
/^[7-9][0-9]{9}$/;
if
(!filter.test(txtCode.value)) {
alert('Enter correct mobile number starting with 7,8,9');
txtCode.focus();
return
false;
}
}
_______________________________________Pin
Code____________________________________________________
validation for Pin Code::: It contains 6 characters
function validateInput10() {
var txtCode =
document.getElementById("<%=TextBox20.ClientID%>");
var filter =
/^[0-9]{6}$/;
if
(!filter.test(txtCode.value)) {
alert('Enter 6 Characters');
txtCode.focus();
return
false;
}
}
___________________________________________Vehicle
Number_____________________________________________
Validation for Vehicle Number:::::like AP11AX1111
function Validpavan() {
var TextBox4 =
document.getElementById("<%=TextBox1.ClientID%>");
var filter =
/^[a-zA-z]{2}\d{2}[a-zA-Z]{2,}\d{4}$/;
if
(!filter.test(TextBox4.value)) {
alert('Enter Correct Vehicle Number');
TextBox4.focus();
return
false;
}
}
__________________________________________alphanumeric starting
with alphabets________________________
validations for alphanumeric starting with alphabets:::
function Validpavan1() {
var txtCode =
document.getElementById("<%=TextBox4.ClientID%>");
var filter =
/^[a-zA-Z][a-zA-Z0-9 ]{2,25}$/;
if (!filter.test(txtCode.value)) {
alert('Enter data in
proper format starting with character');
txtCode.focus();
return
false;
}
}
___________________________________________
Validation for integers::Allowing 1 t0 4 Characters
function ValidateMobileNumber()
{
var txtCode =
document.getElementById("<%=TextBox3.ClientID%>");
var filter =
/^[0-9]{1,4}$/
if
(!filter.test(txtCode.value))
{
alert('Invalid Number. Must Contain Maximum 4 Numbers');
txtCode.focus();
return
false;
}
}
In Textbox:: onblur = "return ValidateMobileNumber()"
----------------------------------------------------------------------------------------------------
Validation for alphabets:: Range 1 to 15 Characters,not allowing
spaces
function validateInput()
{
var txtCode =
document.getElementById("<%=TextBox1.ClientID%>");
var filter =
/^[a-zA-Z]{3,15}$/;
if
(!filter.test(txtCode.value)) {
alert('Enter 3 to 15 Characters');
txtCode.focus();
return
false;
}
}
In Textbox:: onblur = "return validateInput() "
------------------------------------------------------------------------
Validation for alphabets:: Range 1 to 15 Characters, allowing
spaces,some special Characters
function validateInput()
{
var txtCode =
document.getElementById("<%=TextBox1.ClientID%>");
var filter = /^[a-zA-Z
.,;\/@#]{3,15}$/;
if
(!filter.test(txtCode.value)) {
alert('Enter 3 to 15 Characters');
txtCode.focus();
return
false;
}
}
In Textbox:: onblur = "return validateInput() "