Supercharge your RTP Validations with Groovy and RegEx
Master RTP Validations with Groovy and RegEx: A Step-by-Step Tutorial
Supercharge your RTP Validations with Groovy
One way to supercharge your RTP validation is to use RegEx.
RegEx or Regular Expressions can be very powerful in validating inputs. Personally, I am not an expert on Regular Expressions but check out the links below to get a fair idea.
Regex tutorial — A quick cheatsheet by examples
Regex Tutorial — A Cheatsheet with Examples!
Using RegEx for RTP Validation
Let’s start off with creating our script by declaring the RTP to take an email address as input, and then validating if the input is correct or not.
/*RTPS: {rtpAdminEmail}*/
// Create the message bundle
def mbUs = messageBundle (
["EMAIL":"The entered email address ({0}) is not valid. Please recheck email address and try again.",
] )
def mbl = messageBundleLoader(["en" : mbUs])
// validate rtpAdminEmail
validateRtp(rtps.rtpAdminEmail, """^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6})*\$""", mbl, "EMAIL", rtps.rtpAdminEmail.EnteredValue)Here’s what should happen.
Once you get a hang of RegEx, you can create much more sophisticated and complex validations to ensure that the input provided is absolutely correct. And as you can see, it doesn’t take a lot of lines of code to do so!
We’ll explore some more interesting validations in another part.
See it on Medium
See it on LinkedIn






