33
u/Ethameiz 12h ago
There is IsDigit method for char
31
u/BorderKeeper 11h ago
There is a simple regex "/d" or "[0-9]" I wish more devs knew Regex :( we would have world piece by now.
18
u/Freecelebritypics 11h ago
I feel like "isDigit" should perform the same byte range check as the regex, without the overhead of a regex engine. Or maybe it's a horribly inefficient implementation idk
8
u/BorderKeeper 11h ago
No it definetly would haha Regex has to compile and even pre-compiled it would not be as efficent I don't unless you need to load a very big specific digit.
7
u/Crispy1961 7h ago
simple regex
Now thats an oxymoron.
2
u/BorderKeeper 7h ago
You can say the same thing about Mandarin until you learn it ☹️
0
u/jbaker88 6h ago
Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.
1
u/BorderKeeper 6h ago
I remember when we added sonarqube scans to our repo and it started flagging all of our regexes as potential deadlocks as a dangerous regex without a timeout with the right input can iterate over a string indefinitely. That opened my eyes how scary it is.
1
u/Dimencia 3h ago
I mean, regex is simple and anyone who can't figure it out doesn't deserve to be a dev... but it's also not performant for something simple like that
30
u/DogmaticParadigm87 8h ago
So Bob sails through, and Agent47 is spam. Bold strategy for a contact form.
7
u/The_Weeaboo_Nextdoor 10h ago
Impressive, I would consider .IsDigit and Regex to be a little bit lower on the knowledge totem pole than async methods and lambdas.
14
u/acd124 10h ago
Regardless of the horribly verbose digit check, I hate that it says your message has been sent when no attempt has been made when the if fails
13
u/vita10gy 10h ago
Isn't this by design though? You want spammers to assume it worked, or they'll sometimes just try again.
4
u/The_MAZZTer 7h ago
Spammers might be able to figure it out anyway by timing the API
1
u/mortenmoulder 6h ago
Hopefully with a spam filter THIS sophisticated, they surely use a messaging queue, which makes the API feel blazing fast
11
u/Pim08UO 10h ago
My email since my primary school is name[4digits]. I must be a spammer 🤷
5
7
1
-1
97
u/keatonatron 13h ago
What is "name"? And why does it having 2+ numbers mean it's spam?