elclanrs / jq-idealforms-old

The ultimate framework for building and validating responsive HTML5 forms.
665 stars 95 forks source link

Update js/filters.js #38

Closed KorvinSzanto closed 12 years ago

KorvinSzanto commented 12 years ago

More accurate email filter. 

elclanrs commented 12 years ago

I can't see how this is more accurate than the current filter, but maybe it's just me...Could you post an example of what email won't validate with the old regex that will validate with this one or vice versa? I used to have an RFC compliant email regex that was merged before, but the I got this bug, and I decided to just use the simplest regex to check for email to prevent these things from happening.

KorvinSzanto commented 12 years ago

Your regex currently matches m@- as a valid email, which wouldn't be an issue if it didn't update as you type... It seems really inorganic to be typing in an email and see "not a good email" then "good email" as you type korvinszanto@g

My regex matches derp@derp.com or derp@d.co or derp@d.d.d.d.d.d.d.d.d.d.d.d.d.d.d.d.d.co << which is valid. It also matches the ones that were problematic in that bug report.

elclanrs commented 12 years ago

The problem with email regex is that you can always miss a valid one and you don't want that to be invalid... For example with your latest regex this email 0@a won't be valid but it should be according to Wikipedia.

KorvinSzanto commented 12 years ago

A domain can only avoid the tld if you have aliases, which will only apply to aliases you've set on your server. That will never in a practical situation be useful without some strange going ons.

This isn't my project :P if you think this isn't worth while, don't pull it in.

elclanrs commented 12 years ago

Yeah I don't think I'll be changing it, like I said I had problems with email regex before and I think the current regex does the job just fine. In any case you can add your own email filter pretty easily if you need to:

$.extend($.idealforms.filters, {
  commonEmail: {
    regex: /[^@]+@([^@\.]+\.)+[^\.@]{2}/,
    error: 'Must be a valid e-mail address.'
  }
})