length should be [2-10],

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

eg: timesheet 2
    shanti chakra
    shantichakra
    shantichakra2

Recommended Answers

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

$spaced = preg_replace('/ {2,}/', ' ', trim($inputString));
Jump to Post

I got to this:

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

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.

Jump to Post

There are validation filters available in PHP [http://php.net/manual/en/filter.filters.validate.php](and I assume other languages) which can check email

Jump to Post

All 11 Replies

i tried this but how to menstion length{1,10}

^[a-zA-Z0-9](\w+\s?)*$
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

/^[\w-.+]+\@[a-zA-Z0-9.-]+.[a-zA-z0-9]{2,4}$/;

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.