tags:

views:

76

answers:

1

Hi,

I have one question related with regular expression. In my case, I have to make sure that first letter is alphabet, second onwards it can be any alphanumeric + some special characters.

Regards, Anto

+2  A: 

Try something like this:

^[a-zA-Z][a-zA-Z0-9.,$;]+$

Explanation:

^                Start of line/string.
[a-zA-Z]         Character is in a-z or A-Z.
[a-zA-Z0-9.,$;]  Alphanumeric or `.` or `,` or `$` or `;`.
+                One or more of the previous token (change to * for zero or more).
$                End of line/string.

The special characters I have chosen are just an example. Add your own special characters as appropriate for your needs. Note that a few characters need escaping inside a character class otherwise they have a special meaning in the regular expression.

I am assuming that by "alphabet" you mean A-Z. Note that in some other countries there are also other characters that are considered letters.

More information

Mark Byers
anto
@anto: Did you remember the `$` anchor at the end of the regular expression?
Mark Byers
Even after adding $ it did not work. I mean, it takes part up to invalid character as i said above.
anto