chathurad
6 years agoContributor
How to validate a email address from groovy scripting
import net.sf.json.groovy.*; import net.sf.json.groovy.JsonSlurper; def Res = context.expand( '${Users - Request 1#Response}' ) def slurper = new JsonSlurper() def json = slurper.parseText Res def Email = json.email
From the above code I got an array of emails from my response data set.
Now i want to check that all the emails has a "@" sign. and at least one "." .
How can i do this.
For now at least "@" verification is enough
I did by below code.
import net.sf.json.groovy.*; import net.sf.json.groovy.JsonSlurper; def Res = context.expand( '${Users - Request 1#Response}' ) def slurper = new JsonSlurper() def json = slurper.parseText Res def Email = json.email int i =0; Email.each() { assert Email[i].contains('@') log.info Email[i] i++ }