Created
March 31, 2009 09:42
-
-
Save ulinkwo/88130 to your computer and use it in GitHub Desktop.
Some Usefull Validations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//validate string length | |
function ValidLen(s,min,max){ | |
if (s.length < min || s.length > max) { return false; } | |
return true; | |
} | |
// validate email | |
function ValidEmail(s){ | |
var check = /^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/; | |
if (!check.test(s)) { return false; } | |
return true; | |
} | |
// validate url | |
function ValidUrl(s){ | |
var check = /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; | |
if (!check.test(s)) { return false; } | |
return true; | |
} | |
// validate number | |
function ValidNumber(s){ | |
var check = /^[0-9]\d*$/; | |
if (!check.test(s)) { return false; } | |
return true; | |
} | |
// validate ip | |
function ValidIp(s){ | |
var check = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/; | |
if (!check.test(s)) { return false; } | |
return true; | |
} | |
// validate date | |
function ValidDate(s){ | |
var check = /^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/; | |
if (!check.test(s)) { return false; } | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment