Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Core: Add multiple attribute to email method.#2074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
RobJohnston wants to merge2 commits intojquery-validation:master
base:master
Choose a base branch
Loading
fromRobJohnston:1722-email-input-type-and-the-multiple-attribute
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletionssrc/core.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1357,13 +1357,28 @@ $.extend( $.validator, {
},

// https://jqueryvalidation.org/email-method/
email: function( value, element ) {
email: function( value, element, no_multiple ) {

// From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
// Retrieved 2014-01-14
// If you have a problem with this implementation, report a bug against the above spec
// Or use custom methods to implement your own email validation
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
if ( this.optional( element ) ) {
return true;
}
if ( !element.multiple || !no_multiple ) {
return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
} else {

var emails = value.split( /[,]+/ );
var valid = true;

for ( var i in emails ) {
value = emails[ i ];
valid = valid && $.validator.methods.email.call( this, $.trim( value ), element, false );
}
return valid;
}
},

// https://jqueryvalidation.org/url-method/
Expand Down
3 changes: 3 additions & 0 deletionstest/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -440,6 +440,9 @@ <h3></h3>
<input name="year"/>
<button name="submitForm27" value="someValue" type="submit"><span>Submit</span></button>
</form>
<form id="testForm28">
<input type="email" id="email1" name="email1" value="name1@domain.tld,name2@domain.tld" multiple="true">
</form>
<form id="_contenteditableForm">
<div name="first_name" id="first_name" contenteditable placeholder="First Name"></div>
<br>
Expand Down
14 changes: 13 additions & 1 deletiontest/methods.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,7 +100,8 @@ QUnit.test( "url2 (tld optional)", function( assert ) {
} );

QUnit.test( "email", function( assert ) {
var method = methodTest( "email" );
var method = methodTest( "email" ),
v;
assert.ok( method( "name@domain.tld" ), "Valid email" );
assert.ok( method( "name@domain.tl" ), "Valid email" );
assert.ok( method( "bart+bart@tokbox.com" ), "Valid email" );
Expand All@@ -119,6 +120,17 @@ QUnit.test( "email", function( assert ) {
assert.ok( !method( "name,@domain.tld" ), "Invalid email" );
assert.ok( !method( "name;@domain.tld" ), "Invalid email" );
assert.ok( !method( "name;@domain.tld." ), "Invalid email" );

v = jQuery( "#testForm28" ).validate();
method = function( value, param ) {
return $.validator.methods.email.call( v, value, $( "#email1" )[ 0 ], param );
};

assert.ok( !method( "name1@domain.tld,name2@domain.tld", false ), "Invalid single email" );
assert.ok( method( "name1@domain.tld,name2@domain.tld", true ), "Valid multiple emails" );
assert.ok( method( "name1@domain.tld, name2@domain.tld", true ), "Valid multiple emails" );
assert.ok( !method( "name1@domain.tld;name2@domain.tld", true ), "Invalid multiple emails due to separator" );
assert.ok( !method( "name1@domain.tld;name2", true ), "Invalid multiple emails" );
} );

QUnit.test( "number", function( assert ) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp