How do i check to see if a field contains any non-numeric characters?

Feb 24, 2019

Copy link to clipboard

Copied

I want to pull a value from a field and perform calculations on it but if the field contains any non-numeric characters I want it to do nothing.

You can use a regular expression for this. For example:

var v = this.getField("Text1").valueAsString;

if (/\D/.test(v)) {

    // the field contains non-numeric characters

} else {
    // the field is empty or contains only numeric characters

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

97

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

How do i check to see if a field contains any non-numeric characters?

Feb 24, 2019

Copy link to clipboard

Copied

I want to pull a value from a field and perform calculations on it but if the field contains any non-numeric characters I want it to do nothing.

You can use a regular expression for this. For example:

var v = this.getField("Text1").valueAsString;

if (/\D/.test(v)) {

    // the field contains non-numeric characters

} else {
    // the field is empty or contains only numeric characters

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

98

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
Feb 24, 2019 0
Feb 24, 2019

Copy link to clipboard

Copied

You can use a regular expression for this. For example:

var v = this.getField("Text1").valueAsString;

if (/\D/.test(v)) {

    // the field contains non-numeric characters

} else {
    // the field is empty or contains only numeric characters

}

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...
Feb 24, 2019 1