Coder Social home page Coder Social logo

Comments (9)

RobThree avatar RobThree commented on July 20, 2024 5

Though the date pattern is matching on 30/02/2016 for me

Except that feb. 30th doesn't exist 😉

Regarding the HTML tag pattern, that's pretty useful for plain text HTML, like in an editor.

Except that there are a gazillion ways the regex will match incorrectly (demonstrated here) or cause trouble otherwise. Have you read the stackoverflow answer I linked to?

PRs are very welcome if you want to make any improvements yourself.

All the ones I pointed out are very case-specific and hard, if not impossible (html, email for example), to get correct. Though I can think of improvements here-and-there I'd suggest taking them all down; for most, if not all, of the regexes there are better ways of handling and validating the inputs (like simply parsing a date(time) value to 'validate' it or sending an activation e-mail to verify an e-mail address).

Regexes do have their use, I'm not saying they don't. But, as said, for most (if not all) of the examples there are much better solutions.


Edit: Here's more I just stumbled upon.

from regexhub.

lukehaas avatar lukehaas commented on July 20, 2024

Thanks @RobThree some valid points there.
Though the date pattern is matching on 30/02/2016 for me.

Regarding the HTML tag pattern, that's pretty useful for plain text HTML, like in an editor.

I've now removed the password pattern as that was proving particularly controversial.

PRs are very welcome if you want to make any improvements yourself.

from regexhub.

dwelle avatar dwelle commented on July 20, 2024

Regarding the HTML tag pattern, that's pretty useful for plain text HTML, like in an editor.

<b>this html</b><b>would beg the differ</b>

from regexhub.

CSobol avatar CSobol commented on July 20, 2024

Re: Emails. The only true way to validate emails is with basic pattern matching. Something along the lines of looking for @.* is the most you can possibly hope to do.

I completely agree with Rob on that point.

from regexhub.

lukehaas avatar lukehaas commented on July 20, 2024

@CSobol email pattern has now been updated with this PR: #15

from regexhub.

fer22f avatar fer22f commented on July 20, 2024

It also lacks a ^ and $ for the time pattern, just like the date one, otherwise it matches "4;30" when you input "24:00"

from regexhub.

bathos avatar bathos commented on July 20, 2024

I seem to run into a bug with the pattern document.body.innerHTML=flags//whoops ;)

from regexhub.

TraderStf avatar TraderStf commented on July 20, 2024

For the email, several regex can help to filter some bad formats.

Lot of sites are still expecting 'simple' emails, eg. max 3 chars for TLD (.com)!
The question is to know if you want a valid one or one that will work on almost on all sites.

Few filters

Maximum length: 254 due to network protocols, not email specs, search RFC...
Minimum length: 7 like [email protected]

.{7,254}

Rough validation of min/max length blocks:
.{1,248}@.{2,250}\..{2,64}

Enhancing this formula, the 3 lengths, is ?impossible? in regex as you need to know the length of each part, must use javascript, not just regex.

Just for Latin char set, supposing case insensitive is set (/..../i):
[a-z][a-z0-9\._-]{0,246}[a-z0-9]@[a-z][a-z0-9\._-]{0,248}[a-z0-9]\.[a-z][a-z0-9\.]{0,61}[a-z]
(Should verify the above one)

A bit more international, but invalid characters are not filtered (spacesss, tabsss, I think controls are except DEL):

[!-\uFFEF]{1,248}@[!-\uFFEF]{2,250}\.[!-\uFFEF]{2,64}

64 is the maximum, today the maximum existing is 24
XN--VERMGENSBERATUNG-PWB
http://data.iana.org/TLD/tlds-alpha-by-domain.txt

Few links

To test your suppositions:
http://cobisi.com/support/kb/emailverify.net/verification-process/validation-levels

Free Mailgun.com validation api, not just the syntax:
https://www.mailgun.com/email-validation

Explanation of unicode in regex:
http://www.regular-expressions.info/unicode.html

For the lazy one, this one is from a framework, dont remember which one...
But mailgun is ok.
Apparently it respects all the rules, except it does not check the length, see above.

function is_valid_email_address(email_address) { var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_{|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(.([a-z]|\d|[!#$%&'*+-/=?^_{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);

from regexhub.

CSobol avatar CSobol commented on July 20, 2024

The question is to know if you want a valid one or one that will work on almost on all sites.

That's an easy answer. When it comes to email addresses, you never want to stop a valid user from signing up via email address. You would much rather take a hundred junk email address than prevent one valid user from signing up or filling out a form.

from regexhub.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.