Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
'/^[a-z,ñ]+((-| )?[a-z,ñ]+)+((-| )?[a-z,ñ]+)?$/i'

Why doesn't it accept if i only input 1 character?
Posted

1 solution

Simple: you have told it not to!

If I compact this a bit it may be a bit more obvious:
^x+y+(z+)?$
Where x, y, and z are the "phrases" in your regex.
That requires "one or more x", then "one or more y", then "one or more z" - a minimum of three characters.

I don't know exactly what you are trying to achieve, so I can't begin to correct it, but get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions. It will make it pretty obvious what the problem is!
 
Share this answer
 
Comments
Member 10243871 31-Aug-13 4:00am    
I'm using that expression to validate a first Name field.
but the problem is that it doesn't accept it, if i only input 1 character.

I need an expression which can do the ff:
- it must start with a letter
- it can contain two words (ex. mary joy)
- the space bet. the two words should only be 1 space (eg. mary joy)
- it should accept ñ (ex. Niña)
-
OriginalGriff 31-Aug-13 4:21am    
You mean that you reposted this ten minutes later:
http://www.codeproject.com/Answers/646011/Regular-Expression-for-first-name-field
Please don't do that - it duplicates work and wastes time, and that annoys people. If you want to add information, the use the "Improve question" widget instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900