Skip to content
Advertisement

PHP Regular Expression validation to allow only upto 1-5 dots in a Email-ID/string [closed]

In PHP, how to add a regression to validate a string if it has more than 5 dots (.) in a Email-ID/string

For example: asdf.bn.jk.ui.tyqwer.sdfg.qw12@gmail.com

If it has more than 5 or 7 dots, I need to show the validation message. Kindly help please.

Advertisement

Answer

I wouldn’t bother with regex on this, just split the string on your delimiter, count the items and subtract 1.

$s = 'asdf.bn.jk.ui.tyqwer.sdfg.qw12@gmail.com';
$dotCount = count(explode('.', $s)) - 1
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement