I'm trying to create a regular expression with preg_match that can detect a string with the following requirements:
I think that I know how to achieve each requirement individually (maybe one of these is wrong), my problem is that I don't know how to concatenate all in a single expression.
The following scenarios must return 1 (or true).
$string1 = "Mega/lodon";
$string2 = "Megalo.don";
$string3 = "Me@galo/doing";
The following scenarios must return 0 (or false).
$string4 = "Meg@loz=on";
$string5 = "Meglo*don";
$string6 = "Megzlodonx";
$string7 = "=egalodoing";
This is what I'm trying:
preg_match("/[a-zA-Z]{10,}.[\/.@]?.[^=*xyz]/", $string1);
You can use:
^(?=.*[\/.@])[^=*_xyz]{10,}$
Here:
^(?=.*[\/.@]) - checks that after beginning of string(^) somewhere there is any of symbols: /,.,@,[^=*_xyz]{10,} - checks that your line at least 10 symbols and doesn't contain any of *,_,x,y,z,$ - marker of the end of the string, so that no forbidden symbols could be matched after first 10 "good" ones.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With