Skip to main content
Dashmir82
Participating Frequently
August 21, 2018
Answered

only numbers with withespace (javascript)

  • August 21, 2018
  • 2 replies
  • 624 views

Hello,

In a field you can enter only phone numbers (with a 0 before). I have the following script:

var regexp = /\D/

if(regexp.test(event.value)==true)

{

app.alert("Bitte nur Zahlen eingeben: 052 123 45 67",3)

}

else

{

event.target.fillColor = color.transparent

}

This entry may also contain withespaces. but when i write the number with a space, i got the error massage.

What exactly do I have to enter to get a result?

Thank you for your help 🙂

This topic has been closed for replies.
Correct answer try67

Use this code:

if (/^[\d\s]*$/.test(event.value)==false) {

    app.alert("Bitte nur Zahlen eingeben: 052 123 45 67",3);

} else {

    event.target.fillColor = color.transparent;

}

You might also want to reject the incorrect values.

To do that add this code after line #2:

event.rc = false;

2 replies

Dashmir82
Dashmir82Author
Participating Frequently
August 22, 2018

Hi

thank you, that was the solution :-)

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 21, 2018

Use this code:

if (/^[\d\s]*$/.test(event.value)==false) {

    app.alert("Bitte nur Zahlen eingeben: 052 123 45 67",3);

} else {

    event.target.fillColor = color.transparent;

}

You might also want to reject the incorrect values.

To do that add this code after line #2:

event.rc = false;