
January 15th, 2009, 07:14 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Whee! Help to know the language and regex flavor you're dealing with though. Perl?
Code:
/^(?=.{1,14}$)[a-z]+(-[a-z]+ | [a-z]+-)([a-z]+[- ])*[a-z]+$/i
- ^: Starting at the beginning of the string, this:
- (?=.{1,14}$): (ensures that there's 1 to 14 characters and then the end of the string*)
- [a-z]+: checks that there is at least one letter
- (-[a-z]+ : then a hyphen, letters, and a space
- | [a-z]+-): or a space, letters, and a hyphen
- ([a-z]+[- ])*: then some letters and a hyphen or space (repeated any number of times, or not at all)
- [a-z]+$: and finally at least one more letter before the end of the string
/i means case-insensitive.
* Honestly, I'd remove this part and use whatever your language offers to check string length. Like a .length property, strlen function, len() method...
Tested against
Code:
abcdefghijklmn
abcd fghij-lmn
a-cd fghij-lmn
a-cd -ghij-lmn
a-cd fghij-lm-
|