only numbers with withespace (javascript)

Community Beginner ,
Aug 21, 2018

Copy link to clipboard

Copied

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 🙂

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

113

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

only numbers with withespace (javascript)

Community Beginner ,
Aug 21, 2018

Copy link to clipboard

Copied

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 🙂

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

114

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 21, 2018 0
Most Valuable Participant ,
Aug 21, 2018

Copy link to clipboard

Copied

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2018 0
Community Beginner ,
Aug 21, 2018

Copy link to clipboard

Copied

Hi

thank you, that was the solution 🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2018 0