Rajasekhar
Rajasekhar

Reputation: 2455

How to write Regular expression for minimum one character in javascript?

I have small requirement in Regular expression,here I need minimum of one letter of Alphabets and followed by numbers and special characters. I tried the following regular expressions but I'm not getting the solution.

/^[a-zA-Z0-9\-\_\/\s,.]+$/

and

/^([a-zA-Z0-9]+)$/

Upvotes: 3

Views: 21137

Answers (3)

Ja͢ck
Ja͢ck

Reputation: 173562

I need minimum of one letter of Alphabets

[a-z]+

and followed by numbers and special characters.

[0-9_\/\s,.-]+

Combined together you would get this:

/^[a-z]+[0-9_\/\s,.-]+$/i

The /i modifier is added for case insensitive matching of alphabetical characters.

Upvotes: 6

elclanrs
elclanrs

Reputation: 94101

Try this regex:

/^[a-z][\d_\s,.]+$/i

To clarify what this does:

^[a-z] // must start with a letter (only one) add '+' for "at least one"
[\d_\s,.]+$ // followed by at least one number, underscore, space, comma or dot.
/i // case-insensitive

Upvotes: 2

Explosion Pills
Explosion Pills

Reputation: 191749

You need the other character selection to be separate. I'm confused as to what "numbers and special characters" means, but try:

/^[a-z]+[^a-z]+$/i

Upvotes: 0

Related Questions