Buy Now
Sign in

Regular Expression Validation Error

omidhz , August 03 2019, 03:48
O
omidhz 295
August 03 2019, 03:48 #388614
I am using Regex to validate email address because I need to prevent users from using free email accounts such as gmail or outlook and ... .
I have the following and it works fine:
^\b[\w\.-]+@((?!gmail|outlook|hotmail).)[\w\.-]+\.\w{2,4}\b$
The problem is that with the above Regex users can register with abc@GMAIL.com. The above Regex is not case sensitive.
When I test the following line in Regex tested it works but it doesn't work in Chronoform:
^\b[\w\.-]+@((?!(?i)gmail|outlook|hotmail).)[\w\.-]+\.\w{2,4}\b$
I'm not sure why the above line doesn't work in CF 6.
Thanks
GreyHead 64
August 03 2019, 08:36 #388616
Hi omidhz,
The simplest fix is probably to change the email address to all lower case before checking - though the \i flag will usually make the check case-insensitive.
Bob
PS There are many genuine users who have GMail or other similar addresses - are you certain that you want to block them?
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
O
omidhz 295
August 03 2019, 16:22 #388622
Thank you for your reply. I tried to change the characters to lower case, but I can't figure out how. Can you help, please?
Thanks
GreyHead 64
August 03 2019, 17:43 #388623
Hi omidhz,
I think using PHP action with something like this should work
<?php
$this->data('email') = strtolower($this->data('email'));
?>
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
O
omidhz 295
August 03 2019, 19:57 #388625
Thanks Bob,
When I add
$this->data('email') = strtolower($this->data('email'));
to the php in the actions of the page that has the email field, I get error 500.
healyhatman 8
August 04 2019, 09:51 #388637
No.
$this->data('email', strtolower($this->data('email')), true);
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
O
omidhz 295
August 04 2019, 10:37 #388641
Thank you healyhatman.
Your line does not give error message. But it is not doing what I wanted.
Let me know if I'm doing something wrong.
On my page 3 of the form, I have a field called email, I'm using the Regex posted above to block gmail and other free emils listed. I add a php in action of page 3 and your code there. When users type in their email, it still shows uppercase as they type and are still able to register with me@GMAIL.com.
Thanks again for your reply.
GreyHead 64
August 05 2019, 08:16 #388651
Hi omidzh,
The code need to be in the form event that Page 3 submits to.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much