question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I'm sorry, but there's loads of issues...

See original GitHub issue

HTML Tags /^<([a-z1-6]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/

Famous answer

Hex Value /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

Hex HTML/CSS color value maybe, but 0xDEADBEAF is a perfectly valid hex value.

Password /^[a-zA-Z0-9+_-]{6,32}$/

Slowly we’re moving the world to password phrases and everybody should be hashing their passwords. Then why the 32 char limit? And why, for Pete’s sake, are we only allowing a-zA-Z0-9+_- and nothing else? *cries* (see also)

Email /^([a-z0-9+_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,24})$/

Yeah. Just. No. Another famous answer

Positive number /^\d*\.?\d+$/

We don’t all live in the US/UK. (1,234.56 v.s. 1.234,56)

Phonenumber /^\+?[\d\s]{3,}$/

+123 is a valid phonenumber? Where? Phonenumbers are notoriously hard to validate (hence libphonenumber for example).

Date in format dd/mm/yyyy /^(0?[1-9]|[12][0-9]|3[01])([ \/\-])(0?[1-9]|1[012])\2(19[0-9][0-9]|20[0-9][0-9])$/

Failed the very first ‘edge case’ I could come up with: 30/02/2016 but also 1852 or 2150 fail… ( as noted elsewhere).

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems. - Jamie Zawinski

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:8
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
RobThreecommented, Nov 29, 2016

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.

0reactions
CSobolcommented, Dec 14, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why You Over-Apologize and How to Stop
Over-apologizing refers to saying “I'm sorry” when you don't need to. This could be when you haven't done anything wrong or you're taking ......
Read more >
Stop saying 'I'm sorry'—science says it makes people think ...
Saying "I'm sorry," especially when you're not at fault, is an automatic reaction — and chances are you've probably said it a handful...
Read more >
How “I'm Sorry” Can Be Used to Manipulate You
I'm sorry ” carries a lot of weight. Saying it requires to admit wrongdoing and the hurt the wrongdoing has inflicted on the...
Read more >
'I'm sorry' is a term we say a lot. Here's how to actually apologize.
We say "I'm sorry" all the time but we often misuse apologies ... There are many reasons why apologizing can feel difficult and...
Read more >
Toxic People: 12 Things They Do and How to Deal with Them ...
We 've all had toxic people dust us with their poison. Sometimes it's more like a drenching. Know these 12 signs to avoid...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found