문제

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