2015-12-21 89 views
1
email: function(value, element) { 
      // 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.!#$%&'*+\/=?^_`{|}~-][email protected][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); 
     } 

我發現上面jQuery驗證插件代碼這裏電子郵件驗證我換成別人的正則表達式,但它仍然驗證電子郵件作爲「例如@例如,」但在我的應用我想它僅用於驗證類型爲「[email protected]」的電子郵件,只是這個正則表達式只是需要更改或代碼的其他部分,因爲更改正則表達式並不適用於我需要更改電子郵件中的regex JQuery驗證插件

+0

@Naruto它沒有我的情況下 – chris

+0

工作真的,真的只是做一些基本的東西(*[email protected]*),實際上**寫電子郵件發送到特定的地址爲**電子郵件地址往往比首先預期的複雜。 – Jan

回答

2

只需更改最後一個*(零個或多個),以+(一個或多個)來強制至少一個.something

/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-][email protected][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])?)+$/ 
                                    ^
# This is the only change ----------------------------------------------------------------------------------------------------------| 

Online demo

+1

謝謝@GsusRecovery – chris