Created
May 18, 2016 11:11
-
-
Save roe3p/7aa084cc45858ecd0be4a7a40b9fc666 to your computer and use it in GitHub Desktop.
A5 Field validation functions
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
//''------------------------- Validation Functions | |
function isValidDate(s) { | |
var bits = s.split('/'); | |
var d = new Date(bits[2], bits[1] - 1, bits[0]); | |
return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]); | |
} | |
function validate(data, type, maxLen, req){ | |
//debugger; | |
req = (typeof(req) == 'undefined') ? true : req; | |
//check for correct datatype | |
switch(type) { | |
case 'date': | |
if(!isValidDate(data)){ | |
return getMessage('VAL_INVALIDDATE'); | |
} | |
} | |
//check for empty value | |
if(req == true && (data == '' || data == null)){ | |
return getMessage('VAL_EMPTY'); | |
} | |
//check for max length | |
if(typeof(maxLen) == 'number'){ | |
if(data.length > maxLen) | |
return getMessage('VAL_TOOLONG').replace('{length}', maxLen); | |
} | |
return true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment