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

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

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

108

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
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Feb 24, 2019 Feb 24, 2019
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
Adobe Community Professional ,
Feb 24, 2019 Feb 24, 2019

Copy link to clipboard

Copied

LATEST

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
community guidelines