tags:

views:

48

answers:

3

Hi,

I've this regex: ^[\p{L}\p{N}]{1,50}$

  • Accept all numbers and all letters
  • min length: 1
  • max length: 50

I'm trying to add this rule without success:

  • can add \s (spaces) but the text can not have only empty spaces
+3  A: 

If your regular expression implementation supports look-ahead assertions:

^(?!\s+$)[\p{L}\p{N}\s]{1,50}$
Gumbo
This looks like the XML schema regex implementation, which does *not* support look-ahead or look-behind assertions, unfortunately.
Adam Bellaire
Might not be, though. Need the OP to clarify.
Adam Bellaire
@Adam Bellaire: There are many regular expression implementations that support Unicode character properties. But as far as I know, in you don’t specify the start and end in XML as it always matches the whole string.
Gumbo
This regex is working :) thks
emanyalpsid
A: 

allow it and then trim double+ spaces

w35l3y
A: 

Assuming it can't start with a space:

^[\p{L}\p{N}]{1}[\s\p{L}\p{N}]{0,49}$
Stefan Thyberg