Skip to content

Commit c5777fc

Browse files
committed
addMethod: Add custom email method example
1 parent ec20128 commit c5777fc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

entries/jQuery.validator.addMethod.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ jQuery.validator.addMethod("domain", function(value, element) {
4040
<desc>Adds a validation method that checks if a given value equals the addition of the two parameters.</desc>
4141
<code><![CDATA[
4242
jQuery.validator.addMethod("math", function(value, element, params) {
43-
return this.optional(element) || value == params[0] + params[1];
43+
return this.optional(element) || value == params[0] + params[1];
4444
}, jQuery.validator.format("Please enter the correct value for {0} + {1}"));
45+
]]></code>
46+
</example>
47+
<example>
48+
<desc>Adds a custom email validation method that is less strict than the one built-in.</desc>
49+
<code><![CDATA[
50+
jQuery.validator.addMethod("laxEmail", function(value, element) {
51+
// allow any non-whitespace characters as the host part
52+
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@(?:\S{1,63})$/.test( value );
53+
}, 'Please enter a valid email address.');
4554
]]></code>
4655
</example>
4756
<category slug="validator"/>

0 commit comments

Comments
 (0)