tags:

views:

168

answers:

2

in my web application i have text box and i want to prevent the user not start with white space and not start with digit and remaining letters alphanumarics help me thank u

+3  A: 

For ASCII characters you could use:

^[a-zA-Z][a-zA-Z0-9]*$ // Note you don't need the "+" after the first character group.
                       // or...
(?i:^[a-z][a-z0-9]*$)  // Slightly shorter, albeit more unreadable, syntax (?i: ... ) makes the expression case-insensitive

If you want to match empty string just wrap the expression in "( ... )?", like so:

^([a-zA-Z][a-zA-Z0-9]*)?$

If you want to work in Unicode you might want to use:

^\p{L}[\p{L}\p{Nd}]*$

Unicode w. empty string:

^(\p{L}[\p{L}\p{Nd}]*)?$

To read more about unicode possibilities in regex, see this page on Regular-Expressions.info.

Edit

Just collected all possibilities in one answer.

JohannesH
good explanation Mr. JohannesH thank u
Surya sasidhar
+3  A: 

Not to start with white space of alpha numeric: [a-zA-Z]+
Followed by 0 or more alphanumeric: [a-zA-Z0-9]*

Final expression

^[a-zA-Z]+[a-zA-Z0-9]*$
Ramesh Soni
yup it is working Mr. Ramesh Soni. r u from india
Surya sasidhar
what you do ramesh
Surya sasidhar
Of course I am software engineer and yes I am indian
Ramesh Soni