Difference between PHP Regular Expression and JavaScript Regular Expression

Hi, I want to use the below php regex in the spry java script framework, but they do not work with the spry framework, and spry does not allow the user to type !.
1)"/^[\d]+$/"
2)"/^([\x{600}-\x{6FF}]+\s)*[\x{600}-\x{6FF}]+$/u"
3)"/^([\x{600}-\x{6FF}]+\d*\s)*[\x{600}-\x{6FF}]+\d*$/u"
please help me convert them for use in spry infrastructure.

+7
source share
2 answers
 1) /^[\d]+$/ 2) /^([\u0600-\u06FF]+\s)*[\u0600-\u06FF]+$/ 3) /^([\u0600-\u06FF]+\d*\s)*[\u0600-\u06FF]+\d*$/ 

/ u is not supported, as Javascript regexes only supports unicode in terms of code points. \ x {???} (unicode codepoints) must be written \ u ???? in Javascript regex (always 4 digits 0 padded)

In these cases, the following applies to the rest of the regular expression:

  • \ s in javascript is treated as unicode
  • \ d - no, this means that only ASCII digits (0-9) are accepted.

This means that we must specifically allow "alien" numbers, for example. Persian (codepoints 06F0-06F9):

 1) /^[\d\u06F0-\u06F9]+$/ 2) /^([\u0600-\u06FF]+\s)*[\u0600-\u06FF]+$/ 3) /^([\u0600-\u06FF]+[\d\u06F0-\u06F9]*\s)*[\u0600-\u06FF]+[\d\u06F0-\u06F9]*$/ 

(Delete \ d if ASCII digits should not be accepted)

Not sure what the brackets should do in Example 1, they could initially be written:

 1) /^\d+$/ 

But to add Persian numbers, we need them, see above.

Update

The Spry mask mask, however, only requires that the regular expression be applied to each character entered, i.e. we actually cannot match patterns, this is just a β€œlist” of accepted characters in all places, in which case:

 1 ) /[\u06F0-\u06F9\d]/ // match 0-9 and Persian numerals 2 and 3) /[\u0600-\u06FF\d\s]/ // match all Persian characters (includes numerals), 0-9 and space 

Delete \ d again if you do not want to accept 0-9.

Update 2

Now ... using regex to check with Spry:

 var checkFullName = function(value, options) { // Match with the by now well-known regex: if (value.match(/^([\u0600-\u06FF]+\s)*[\u0600-\u06FF]+$/)) { return true; } return false; } var sprytextfield = new Spry.Widget.ValidationTextField( "sprytextfield", "custom", { validation: checkFullName, validateOn: ["blur", "change"] } ); 

A similar user function can be performed for case 3.

See Adobe Lab Examples

+8
source

Do you pass them as strings or as regular expression objects? Try to remove "characters from the regular expression".

The 'u' flag is a bit trickier. You may need to explain what the 2nd and 3rd regular expressions are trying to do.

+2
source

All Articles