Forums

Home » Liferay Portal » English » x. Miscellaneous

Combination View Flat View Tree View
Threads [ Previous | Next ]
Gary Daigle
Web Form validation not validating
September 12, 2012 7:23 AM
Answer

Gary Daigle

Rank: New Member

Posts: 8

Join Date: August 8, 2012

Recent Posts

Hello everyone,

I'm having an issue with the Web Form portlet not performing validation. I've set "validation.script.enabled=true" in my portal-ext.properties, restarted the Liferay service, and cleared my cache. I am using GA2 (6.1.1)

I'm attempting to validate phone numbers and email addresses, I've tried the following validation code, but no matter what I enter, the form submits without any errors:

Phone Number:
var phoneExp = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
if(currentFieldValue.match(phoneExp)) {
return true;
}else {
return false;
}


Email Address:
var alphaExp = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
if(currentFieldValue.match(alphaExp)) {
return true;
}else {
return false;
}

I've also tried:

if (currentFieldValue.indexOf("@")<1 || currentFieldValue.indexOf(".")<currentFieldValue.indexOf("@")+2 || currentFieldValue.indexOf(".")+2>=currentFieldValue.length)
return false;
else return true;
jack crawford
RE: Web Form validation not validating
September 12, 2012 10:02 PM
Answer

jack crawford

Rank: New Member

Posts: 1

Join Date: September 12, 2012

Recent Posts

Try to change your browser hop it will work.
Gary Daigle
RE: Web Form validation not validating
September 13, 2012 5:47 AM
Answer

Gary Daigle

Rank: New Member

Posts: 8

Join Date: August 8, 2012

Recent Posts

I've already tested this under Chrome, Firefox, and Internet Explorer.
Tad Fox
RE: Web Form validation not validating
October 9, 2012 11:08 AM
Answer

Tad Fox

Rank: New Member

Posts: 10

Join Date: April 19, 2012

Recent Posts

First, make sure "optional" isn't checked on the fields. Here's what I'm using that works:

Phone number:
var regexObj = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
if (regexObj.test(currentFieldValue)) {
return true;
} else {
return false;
}

Email:
var x=currentFieldValue;
var atpos=x.indexOf("\x40");
var dotpos=x.lastIndexOf("\x2e");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
return false;
} else {
return true;
}

If these are still not working, I'm pretty sure you have something else conflicting it.