Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

How to restrict user to type only certain characters in a field ?

Avatar

Level 4

Hi,

I am using date field control in my PDF form. It is editable and user can type into it w/o using the calender control. I want that user can only type from '0-9' and ' - ' (hyphen), no other than that. Please help as I am not getting any clue for it.

Thanks in advance.

-

Abhinav

1 Reply

Avatar

Former Community Member

If you want to restrict custom date entry you could use a regular expression such as

// form1.page1.subform1.dob::exit - (JavaScript, client)

var regExp = /^\d{1,2}\-\d{1,2}\-\d{4}$/

var str = this.rawValue;

if (!(regExp.test(str))) {

  xfa.host.messageBox("The date of birth must be in the format MM-DD-YYYY, M-DD-YYYY or MM-D-YYYY.");

}

Steve