New to using regex vcustom validation | XM Community
Skip to main content
Question

New to using regex vcustom validation

  • August 31, 2023
  • 2 replies
  • 53 views

Forum|alt.badge.img

Hi all-

 

New to useing regex here and have read through quite a few of the forums on regex, however the use cases I’m seeing people use are only getting me about halfway to the validation I’m trying to add. I am trying to add validation so that the text needs to alwasy start with “ClassID” and end in a date format with no “/” or spaces, ie “ClassID083123”. Any help would be appreciated.

 

Thank you

2 replies

Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • September 1, 2023

@wcunningham You can use this

^ClassID(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])(\d{2})$
 

Note: This only give you a number entry validation, it does not take into account leap years or month-specific day limits. If you need more accurate date validation, you might need to consider additional logic beyond regex.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • September 1, 2023

@wcunningham,

You could hide the text input and create your own input, and use cleave.js to make sure a valid date is entered. HTML would be something like:

ClassID<input id="classIdDate" type="text">

Then use the concatenation of ClassID and the date to set the value of the hidden input.

For validation,  you only need to check that the length of the input is 13.