user3746259
user3746259

Reputation: 1581

regex (php pcre) not validating Currency Sign

I am using the following regex to check an input field. I want to allow all currency symbols:

/^[\w\s\-\#?\!:='\(\)\p{Sc}]+$/

It is working - except for the sign.

\p{Sc} would mean "match all currencies". The $ sign is e.g. working - but the sign gets kicked out.

Where is my mistake? Regards.

Upvotes: 0

Views: 59

Answers (1)

nhahtdh
nhahtdh

Reputation: 56819

Use u flag to enable UTF mode, so that the pattern and the input string are treated as Unicode string (in UTF-8 encoding). Without u flag, matching operates on bytes and is not Unicode-aware.

/^[\p{Sc}\w\s#?!:='()-]+$/u

I have also removed unnecessary escape \ and placed - at the end of the character class to avoid escaping.

Upvotes: 1

Related Questions