I have a number of Dynamic Actions in my Oracle Apex 4.2 page with action "Execute Javascript Code" on a phone number entry field:

$s("P40_MOBILE_PHONE", $v("P40_MOBILE_PHONE").replace(/[()-\s]+/g, ''));

This works in IE and Chrome. In Firefox, however, it not only doesn't work, but it causes all other dynamic actions on the page to stop working entirely.

The only difference between this and the other dynamic actions seems to be the use of string.replace(/[()-\s]+/g, ''). This is supposed to strip any spaces, (, ) and - characters from the phone number.

有帮助吗?

解决方案

As @dandavis said in a comment, escaping the dash works (no need to escape parentheses, though).

If you try to run the code

/[()-\s]+/

you get

SyntaxError: invalid range in character class

That's because Firefox is trying to use the dash as a range character, not dash.

To fix it, you can:

  • Escape the dash: /[()\-\s]+/
  • Place the dash at the beginning or end: /[-()\s]+/, /[()\s-]+/

其他提示

For future reference, changing the regex as follows fixed the problem:

replace(/[\(\)\-\s]+/g, '')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top