Created
March 26, 2017 09:30
-
-
Save rijkvanzanten/d3d35db6bb127b95d4db10ea650b8433 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Validates RGB(a) value | |
* @param {Number} r | |
* @param {Number} g | |
* @param {Number} b | |
* @param {Number} [a=0] | |
* @return {Boolean} | |
*/ | |
function isValidRGB(r, g, b, a) { | |
a = a || 0; | |
if(typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number' || typeof a !== 'number') return false; | |
var regex = /\b(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\b/; | |
if( | |
regex.test(r) && | |
regex.test(g) && | |
regex.test(b) && | |
a >= 0 && a <= 1 | |
) return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment