0

I have this code from a javascript

/+\uFF0B0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9u/

after some read about php & \u support I convert it to \x

/\+\x{FF0B}0-9\x{FF10}-\x{FF19}\x{0660}-\x{0669}\x{06F0}-\x{06F9}/u

but still I'm not able to use it in php

$phoneNumber = '+911561110304';
$start = preg_match('/\+\x{FF0B}0-9\x{FF10}-\x{FF19}\x{0660}-\x{0669}\x{06F0}-\x{06F9}/u', $phoneNumber,$matches);

the matches will be null!

how to fix this?

1
  • 2
    You sure you copied that correctly? Shouldn't the JS regex also have character classes at least (square brackets) and some repetition modifier at the end? Commented Nov 16, 2011 at 5:23

1 Answer 1

1

It looks like you want to match an ASCII plus sign or its Japanese Halfwidth equivalent, followed by one or more digits from a few different writing systems. But, as @mario observed, you seem to be missing some square brackets. The JavaScript version probably should be:

/[+\uFF0B][0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]+/

(I couldn't see any reason for the u at the end, so I dropped it.) The PHP version would be:

'/[+\x{FF0B}][0-9\x{FF10}-\x{FF19}\x{0660}-\x{0669}\x{06F0}-\x{06F9}]+/u'

Of course, this will allow a mix of ASCII, Arabic and Halfwidth characters in the same number. If that's a problem, you'll need to break it up a bit. For example:

'/\+(?:[0-9]+|[\x{0660}-\x{0669}]+|[\x{06F0}-\x{06F9}]+)|\x{FF0B}[\x{FF10}-\x{FF19}]+/u'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.