C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Javascript for Validations and Email check


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: Validations
Author: Ashok KandasamyMember Level: Diamond    
Rating: Points: 10





function FilterNumberInput()
{

if(57 {
event.returnValue=false;
}

if(event.keyCode==46)
{
event.returnValue = true;
}
}

function FilterChracterInputs()
{

if(122 {
if(90 {
event.returnValue = false;
}

}
if(event.keyCode==46||event.keyCode==32||event.keyCode==95)
{
event.returnValue = true;
}
}


function SubmitProcessevent(button)
{
if(event.keyCode == 13)
{
document.all[button].click();
event.returnValue = false;
}
else
{
return true;
}
}


function emailCheck (emailStr)
{
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null)
{
alert("Your Email Address must be valid!")
return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null)
{
alert("Your Email Address must be valid!")
return false;
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null)
{
for (var i=1;i<=4;i++)
{
if (IPArray[i]>255)
{
alert("Your Email Address must be valid!")
return false
}
}
return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null)
{
alert("Your Email Address must be valid!")

return false
}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
{
alert("The Email Address must end in a three-letter domain, or two letter country.")
return false
}
if (len<2)
{
alert("Your Email Address is invalid.")

return false
}
return true;
}

function isUrl(s)
{
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}


function trim(inputString)
{
if (typeof inputString != "string")
{
return inputString;
}
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ")
{
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ")
{
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1)
{
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length);
}
return retValue;
}

function FilterDecimal(textValue)

{
var nDecimal = 0;
var i;
var x;
var xTxt=textValue.value;
//var xTxt = document.getElementById("ctl00_ContentPlaceHolder1_txtBasicDuty").value;
var txtLen= xTxt.length;
for(i = 0; i < txtLen; i++)
{
x = xTxt.substr(i, 1);
if(x == ".")
nDecimal = nDecimal + 1;
if(nDecimal > 1)
{
alert("You have entered more than one decimal point!\nPlease only enter one!");
textValue.value="";
textValue.focus();
return false;
}
}
}

function IgnoreDecimal(textValue)

{
var nDecimal = 0;
var i;
var x;
var xTxt=textValue.value;
//var xTxt = document.getElementById("ctl00_ContentPlaceHolder1_txtBasicDuty").value;
var txtLen= xTxt.length;
for(i = 0; i < txtLen; i++)
{
x = xTxt.substr(i, 1);
if(x == ".")
nDecimal = nDecimal + 1;
if(nDecimal > 0)
{
alert("You have entered decimal point!\nPlease ignore decimal point!");
textValue.value="";
textValue.focus();
return false;
}
}
}









Responses

Author: Kapil Dhawan    17 Jun 2008Member Level: Gold   Points : 2
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you
Regards,
Kapil








Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: RegEx for credit card validation
Previous Resource: How to strip all special characters including space in vb.net
Return to Discussion Resource Index
Post New Resource
Category: Validations


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use