length should be [2-10],

should accept [a-zA-z0-9],accept one space in between characters.

eg: timesheet 2
    shanti chakra
i tried this but how to menstion length{1,10}

Member Avatar

WOuld replacing multiple spaces with a single space be any use?

$spaced = preg_replace('/ {2,}/', ' ', trim($inputString));
Member Avatar

The reason I'm asking is do you want to use a preg_replace for simple mistakes like multiple spaces or are you just going for straight unequivocal validation which will spit out anything with a double space?

I got to this:

^[a-zA-Z0-9](?:[a-zA-Z0-9]|[ ](?=[^ ]*$)){0,8}[a-zA-Z0-9]$

thank you so much pritaeas it helped me

regular expression for valid email


E-mail is dangerous to do with a regex, as it allows for invalid ones to get through. There is no guarantee with such a check. It's much better to send a confirmation link to an e-mail address.