Regular Expression Validation Error

omidhz 03 Aug, 2019
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 03 Aug, 2019
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?
omidhz 03 Aug, 2019
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 03 Aug, 2019
Hi omidhz,

I think using PHP action with something like this should work

<?php
$this->data('email') = strtolower($this->data('email'));
?>

Bob
omidhz 03 Aug, 2019
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 04 Aug, 2019
No.
$this->data('email', strtolower($this->data('email')), true);
omidhz 04 Aug, 2019
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 05 Aug, 2019
Hi omidzh,

The code need to be in the form event that Page 3 submits to.

Bob
This topic is locked and no more replies can be posted.