I need to make a new method for jQuery Validator and don't know where to start.
I would like it check that the email entered includes: '@specificdomain.com'.
But that it is also the very last part of the input. For example @specificdomain.comChris would not do.
<script type="text/javascript">
jQuery.validator.addMethod("mustinclude", function(value, element) {
return this.optional(element) || value == ?
}, "must include @specificdomain.com at the end of the text input");
$(document).ready(function(){ .....
So far I've only come across value == value.match(), hence this is where I've got stuck.
Cheers Chris
jQuery.validator.addMethod('matchDomain', function(value, element) {
var s=value;
var split = s.split('@');
var regex = /^([a-zA-Z0-9_.+-])+$/;
var s2="@allcoles.com";
var optionalValue = this.optional(element);
if (optionalValue) {
return optionalValue;
}
if(regex.test(split[0]) && s2.equals(split[1]))
{
return true;
}
else
{
return false;
}
}, 'Please specify a @allcoles.com email');
.addMethod()
examples inside theadditional-methods.js
file. Looking at those rules would be a great place to learn how it's done. – Sparky Mar 16 at 17:43