Allowing field entry for either numbers only or a specific phrase

Avatar

Avatar

Dave_Erho

Avatar

Dave_Erho

Dave_Erho

02-10-2017

I have a field on a form that needs to only accept numbers (with no dashes, spaces, commas, etc.) OR accept a specific phrase. In this case "Not Available".

In most cases the user with enter a number. But there are instances where the number is not known, so we want to allow the phrase Not Available to be entered into that field.

Right now, I have this code in the change event

if (xfa.event.newText.match(/[^0-9]/ || /\sNot Available\s/))    

{

xfa.event.change = "";

}

It works for only allowing numbers to be typed, but doesn't work for allowing the Not Available to be typed or selected from a drop-down.

I'm not very familiar with these types of expressions, so help is appreciated.

Thanks,

Dave

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

Dave_Erho

Avatar

Dave_Erho

Dave_Erho

02-10-2017

The change below almost works perfectly. However, since this field is a drop-down, I need it to also allow pressing the down arrow and the enter key to select the "Not Available" option if they don't want to use the mouse. Anyone have the syntax for that?

if (this.rawValue.match(/\s+Not Available\s+/g))

{

}    

else if (xfa.event.newText.match(/[^0-9]/))

{

xfa.event.change = "";

}