Click here to Skip to main content
14,327,007 members
Rate this:
Please Sign up or sign in to vote.
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:


But I dont know hoy to add the symbol part.
Thanks a lot for your help!
It depends on what do you mean by "symbol", exactly. You need to formulate all very accurately and formally...
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
which is about the same, but includes more accented characters.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100