regex - Setting regular expression to validate URL format in Adobe CQ5 -
i want validate url inside textfield using adobe cq5, set properties regex , regextext usual, reason not working:
<facebook jcr:primarytype="cq:widget" emptytext="http://www.facebook.com/account-name" fielddescription="set facebook url" fieldlabel="facebook" name="./facebookurl" regex="/^(http://www.|https://www.|http://|https://)[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$/" regextext="invalid url format" xtype="textfield"/>
so when type inside component can see error message @ console:
uncaught typeerror: this.regex.test not function
to more accurate error comes line:
if (this.regex && !this.regex.test(value)) {
i tried several regular expressions , none of them worked. guess problem regular expression itself, because in other hand have other regex evaluate email address, , works fine:
/^[a-za-z0-9]+[\\._]*[a-za-z0-9]*@[a-za-z.-]+[\\.]+[a-za-z]{2,4}$/
any suggestions? in advance.
the syntax of regex seems treat forward slashes (/) special characters. since want parse url containing slashes, guess should escape them twice this: '\\/' instead of '/'. result be:
/^(http:\\/\\/www.|https:\\/\\/www.|http:\\/\\/|https:\\/\\/)[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/
you need escape them twice because string compiled regex must contain '\/' escape slashes, introduce backslash in string have escape backslash too.
Comments
Post a Comment