Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
2.67/5 (2 votes)
See more:
Greetings friends,

I need some help on regular expressions, Im pretty new on this.
Here are the rules it must have:

- Admits symbols +#$&% ñ Ñ and space and it may be at the beginning, end or middle of the field (any part)
- If there is any symbol or space, it must have a letter or number on any part of the expression (it cant be only symbols)
- Is a required field.

I was thinking on something like this:

[A-Za-z0-9Ññ]+

But I dont know hoy to add the symbol part.
Thanks a lot for your help!
Posted
Comments
Sergey Alexandrovich Kryukov 23-May-13 9:10am    
It depends on what do you mean by "symbol", exactly. You need to formulate all very accurately and formally...
—SA
Member 7869883 23-May-13 9:20am    
It allows A-Z a-a 0-9 ñ Ñ +#$&% and spaces
But if the user enters +#$&% or an space (at any location of the field), it must have at least one letter or number.
Thanks :)

1 solution

This is not a "good" regex problem: what you really want to do is use a regex to find if a string contains any "special" characters, then count the number of non-special characters. But your description basically comes down to: you can use any characters you like, but you must have at least one non-special character (because you can have specials anywhere, but you need at least one non-special, but you don't have to have any specials.) So use the regex you have - or better, use this:
\w+
which is about the same, but includes more accented characters.
 
Share this answer
 

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