Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to make text field only accpet digits?

Avatar

Level 1

Hello everyone

I wann know how to make a text field only accpet digits (0,1,2 ...9)? In Acrobat, it's very easy to set, but in LiveCycle, looks it needs some custom JavaScript, can anyone please provide help?

The following codes can't work in LiveCycle, how to make it work?

if(!event.willCommit)
    event.rc = !isNaN(event.change) || event.change == "." || (event.change == "-" && event.selStart == 0);

Thanks

3 Replies

Avatar

Former Community Member

Regular expressions are a good option. The following uses \D to match any character that is not a digit.

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


if (!(this.isNull)) {

  var tf1 = this.rawValue;

  var regExp = /\D/;

  if (regExp.test(tf1)) {

    xfa.host.messageBox("tf1 must be numeric");

  }

}

Steve

Avatar

Level 1

Thanks Steve, your codes are what I want.