Skip to content

Instantly share code, notes, and snippets.

@abhijeetchopra
Last active July 31, 2016 06:12
Show Gist options
  • Save abhijeetchopra/916d95f8a622c8e7da96dca7e4ca3978 to your computer and use it in GitHub Desktop.
Save abhijeetchopra/916d95f8a622c8e7da96dca7e4ca3978 to your computer and use it in GitHub Desktop.
RegularExpression
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>RegularExpression</title>
<script>
var str;
function buttonClick(){
alert(validateRegEx(t1.value));
}
function validateRegEx(str) {
/**
* Tests if given string matches with RegEx
* @param {String} str
* @return {Boolean} true/false
*/
result = /[^0123456789+\s]/.test(str);
if((result == false)&&(str.length>4)){
return true;
}
else{
return false;
}
}
</script>
</head>
<body>
<input id="t1" type="text">
<button onclick="buttonClick()">Test String</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment