Skip to main content
Participant
October 31, 2024
Answered

Text field must begin with a numerical value

  • October 31, 2024
  • 2 replies
  • 642 views

Hello Community!  

I hope someone can please help me with this problem.  I have searched for an answer to this all afternoon.

I need to create a text field that requires the user to begin their entry with digits and then any combination of letters and numbers. The number of characters in the field will vary but it must begin with 4 or 5 digits. These are some examples of how the entries would look:

  • 61220.1CS.1047849
  • 53456.1.1122714
  • 42406.FY22.1.5001141
  • 81100.000001.001.221.220700.01

I've seen a lot about the custom validation script in the field properties and regex, but I can't figure it out.

Please help! I don't know where to begin.

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

You can use this code as the field's custom Validation script (I assume there needs to be a period after the digits. If not, then you need to clarify whether it's four or five digits that the user must enter):

 

if (event.value) {
	if (/^\d{4,5}\./.test(event.value)==false) {
		app.alert("Invalid value.");
		event.rc = false;
	}
}

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 31, 2024

You can use this code as the field's custom Validation script (I assume there needs to be a period after the digits. If not, then you need to clarify whether it's four or five digits that the user must enter):

 

if (event.value) {
	if (/^\d{4,5}\./.test(event.value)==false) {
		app.alert("Invalid value.");
		event.rc = false;
	}
}
Participant
November 4, 2024

Thank you so much! Yes, the periods do need to be included so It works perfectly!

Thank you