Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching ONLY Numbers / Persian Characters And Latin

Tags:

regex

php

i need a regex code that matches Numbers/Persian Characters And Latin ( A-Z )

i wrote the following code

preg_match("/[A-Za-z\s\x{0600}-\x{06FF}0-9_\.\- ]/u",$_POST['input'] )

and works fine .

but there is a problem, i dont want to input have any ( @,#,!,%,$,&,* ) characters .

any ideas?

like image 293
Saeid Khaleghi Avatar asked Jan 26 '26 14:01

Saeid Khaleghi


1 Answers

Just use an negative lookahead assertion in your regex to check that there is no such character. Place this at the beginning of your regex. I mean just after the /.

(?!.*[(@#!%$&*)])

For example:

preg_match("/^(?!.*[(@#!%$&*)])[A-Za-z\s\x{0600}-\x{06FF}0-9_\.\- ]+$/u",$_POST['input'] )
like image 62
Sabuj Hassan Avatar answered Jan 28 '26 02:01

Sabuj Hassan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!