Reputation: 1400
I want to use Parsley js to allow only alphabetic, dashes and underscores. this is my code
<html>
<head>
<title>Alphadash</title>
<link rel="stylesheet" href="css/Parsley.css">
</head>
<body>
<form id="demo-form" data-parsley-validate="">
<label>Please enter a alphadash:</label>
<input type="text" name="slug" required data-parsley-alphadash="">
<input type="submit">
</form>
<script src='js/jquery.min.js'></script>
<script src='js/Parsley.min.js'></script>
<script type="text/javascript">
window.Parsley.addValidator('alphadash', {
validateString: function(value) {
return true == (/^\d+$/.test(value));
},
messages: {
en: 'Only alphabetic letters, dashes and underscores allowed.'
}
});
</script>
</body>
</html>
I know you can do that with Pattern build-in function. but in my case i want to use a custom function.
Upvotes: 2
Views: 4882
Reputation: 1400
you should just add
return true == (/^[a-z-_]+$/.test(value));
Upvotes: 1