stefanosn
stefanosn

Reputation: 3324

preg match php a-zA-Z0-9 and space

if (preg_match ('/[^a-zA-Z0-9]/i', $getname)) {

i use this preg_match pattern to check if a string in php contains other charachters than a-zA-Z0-9. i want to add to the pattern the space...i use '/[^a-zA-Z0-9 ]/i' but is not working ... how should i do it?

i want to allow spaces including a-zA-Z0-9

Upvotes: 6

Views: 36496

Answers (3)

Chander Pal
Chander Pal

Reputation: 11

preg_match("/[^A-Za-z'-'_' ']/", 'string')

if you want to use space in your input field then you have to use this ' ' not this ''.

mention space between ' '

Upvotes: 1

asdasd
asdasd

Reputation: 181

preg_match('/^[a-zA-Z0-9 ]+$/', 'string')

Upvotes: 1

yoda
yoda

Reputation: 10981

if (preg_match ('/[a-zA-Z0-9 ]/', $getname)) {

Upvotes: 5

Related Questions