Pradeep
Pradeep

Reputation: 1292

Regex for single character and empty String(Not white space)

I have a optional fields in which I have to accept only single character and I should also accept empty string. Ex: if I have a middle name field, in which it accepts single char. but in future if he don't want any middle name on his account then I should persist empty to the middle name in the database.

I used the below regexp. but it is not working to accept empty string [^$]|[A-Za-z]+

Could some one help me on this?

Upvotes: 0

Views: 1965

Answers (1)

Bohuslav Burghardt
Bohuslav Burghardt

Reputation: 34776

How about ^[A-Za-z]?$ (one or zero letters)?

Upvotes: 2

Related Questions