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

All 11 Replies

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

^[a-zA-Z0-9](\w+\s?)*$
^[a-zA-Z0-9](\w+\s?)*$
Member Avatar for diafol

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.