Skip to content

Instantly share code, notes, and snippets.

@agungyuliaji
Last active December 13, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agungyuliaji/4959700 to your computer and use it in GitHub Desktop.
Save agungyuliaji/4959700 to your computer and use it in GitHub Desktop.
Validate Text Field with some words
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<input id="test">
<script>
var thisExpressions = [/abi/, /dark/, /hehe/];
function matchInArray(string, expressions) {
var len = expressions.length,
i = 0;
for (; i < len; i++) {
if (string.match(expressions[i])) {
return true;
}
}
return false;
};
$('#test').blur(function(){
matchInArray($(this).val(), thisExpressions)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment