Skip to main content
Participant
February 24, 2019
Answered

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

  • February 24, 2019
  • 1 reply
  • 496 views

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.

This topic has been closed for replies.
Correct answer try67

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

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 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

}