Last active
October 17, 2016 21:42
-
-
Save englishextra/b5aaef8b555a3ba84c68a6e251db149d to your computer and use it in GitHub Desktop.
Check if string represents a valid HTML id
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
/*! | |
* Check if string represents a valid HTML id | |
* gist.github.com/englishextra/b5aaef8b555a3ba84c68a6e251db149d | |
* jsfiddle.net/englishextra/z19tznau/ | |
* @param {String} a text string | |
* @param {Int} [full] if true, returns with leading hash/number sign | |
* isValidId(a,full) | |
*/ | |
var isValidId = function(a, full) { | |
return full ? /^\#[A-Za-z][-A-Za-z0-9_:.]*$/.test(a) ? !0 : !1 : /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(a) ? !0 : !1; | |
}; | |
alert(isValidId("#dffdfddffd",!0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment