To Trim the Empty space on both side
String.prototype.trim = function() {return this.replace(/^\s+\s+$/g,"");}
//Checking Blank Values
if (document.getElementById("txtName").value.trim()=="")
{
alert("Name Field can not be blank");
document.getElementById("txtName").focus();
return false;
}
//Checking AlphaNumeric Values
if (CheckKeyIsAlphanumerics(document.getElementById(txtName)))
return false;
else
return true;
function CheckKeyIsAlphanumerics(str)
{
var string = str.value.trim();
var iChars = "01234546789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (var i = 0; i lt; string.length; i++)
{
if (iChars.indexOf(string.charAt(i)) == -1)
return true;
}
return false;
}
To allow special characters in condition means add the special character in the iChars Variable.
//EmailValidation in the Textbox
if (isValidEMailID(document.getElementById("txtEmail")))
return true;
else
return false;
function isValidEMailID(oControl)
{
if(oControl.value != "")
{
if((/([A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}][A-Za-z]\w*(\.[A-Za-z]\w*)+)$/.test(oControl.value))==false)
{
alert("Invalid Email Format.");
oControl.value ="";
return false;
}
}
return true;
}
Pass the Control ID as Parameter for the Function.
Captions
- Asp.Net (9)
- ASP.Net Tips (1)
- C# (7)
- Computer (1)
- Internet Explorer (5)
- Java Script (11)
- Shortcut Keys (4)
- SQL Programming - Common Mistakes (11)
- Sql Server (22)
- Sql Server Definitions (8)
- Sql Server Test (2)
- SSRS (2)
About Me
- Vasanth.S
- I'm just normal guy who like to travel, addicted to TV and Computer, Playing Computer Games and Watching Movies and many more. Have lot of idea and quote in life
My Blog List
-
-
Pass data from one page to another using post15 years ago