问题
I want to overwrite password pattern provided by foundation(zurb) but its not identifying my overwritten regular expression and generated error according to its by default expression. By default,passwords validation provided by foundation is "must be at least 8 characters with 1 capital letter, 1 number, and one special character". For that I have used following:
1)
<head>
<script>
$(document)
.foundation()
.foundation('abide', {
patterns: {
new: ^[a-zA-Z]\w{3,14}$,
}
});
</script></head>
<body>
<form class="custom" data-abide>
<div class="row">
<div class="large-12 columns">
<label>Password <small>required</small></label>
<input type="password" pattern="new" required >
<small class="error" data-error-message="">validation error.</small>
</div>
</div>
</form>
</body>
2)
<form class="custom" data-abide="">
</form>
3)Directly used pattern in input tag:
<input type="password" pattern="^[a-zA-Z]\w{3,14}$" required >
But all these are not working.Please suggest me something to resolve my problem.
You can find the sample program - here
回答1:
Replacing pattern called password
does the trick. Change
<script>
$(document).foundation();
</script>
at the bottom of index.html
to the following code:
<script>
$(document)
.foundation()
.foundation('abide', {
patterns: {
password: /^\w{3,14}$/,
}
});
</script>
Note that the regex you provided (^[a-zA-Z]\w{3,14}$
) should be written as /^[a-zA-Z]\w{3,14}$/
in JavaScript.
回答2:
Update the value before running foundation:
<script>
Foundation.libs.abide.settings.patterns.password = /^\w{3,14}$/;
$(document).foundation();
</script>
来源:https://stackoverflow.com/questions/18695164/foundation-4unable-to-overwrite-its-regular-expression-to-validate-password