Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joshua Bertrand
Client Side Web Form Validation Help
August 24, 2012 9:52 AM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

My organization is using 6.1 EE with the "Web Form" portlet on several of our sites. We are needing to add validation scripts to our forms to ensure that a Phone Number holds numeric values and is at least 8 characters and that email address's must include @ symbol.

My attempts for the javascript code have not worked (although I am still in my early stages of learning javascript).... my question is.. are there any javascript examples out there that I can copy for this? I have been looking for the last hour and have been unsuccessful in finding anything that works.

Thank you for any help you can provide.
Vishal Panchal
RE: Client Side Web Form Validation Help
August 24, 2012 11:22 AM
Answer

Vishal Panchal

Rank: Expert

Posts: 264

Join Date: May 20, 2012

Recent Posts

Hi Joshua Bertrand,

Please take a look at this link

It will surely help you to learn basic validations using javascript as well as to get your desired..!!emoticon


Thanks & Regards,
Vishal R. Panchal
Joshua Bertrand
RE: Client Side Web Form Validation Help
August 24, 2012 1:27 PM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

Thank you for the link. It was very helpful in understand the correct way to code a validation script. However, applying this to the Web Form portlet has still been unsuccessful and my form still submits when invalid characters are presented. Does anyone just have code that they use that you wouldn't mind providing?

Thank you.
Shinn Lok
RE: Client Side Web Form Validation Help
August 24, 2012 2:43 PM
Answer

Shinn Lok

LIFERAY STAFF

Rank: Junior Member

Posts: 59

Join Date: January 14, 2011

Recent Posts

Phone Number:
1if(!/\D/.test(currentFieldValue) && currentFieldValue.length >= 8)
2return true
3else return false;

Email Address:
1if (currentFieldValue.indexOf("@")>=0)
2return true;
3else return false;
Hitoshi Ozawa
RE: Client Side Web Form Validation Help
August 24, 2012 6:55 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 8000

Join Date: March 23, 2010

Recent Posts

if(!/\D/.test(currentFieldValue) && currentFieldValue.length >= 8)


Any reason to using (!/\D/ instead of /\d/ and just use .search instead of .test and just specifiy number of digits with [8] instead of using length?

if (currentFieldValue.indexOf("@")>=0)


This is a very primitive validation. Should use regular expression so it can be expanded to also test if the domain contains "." and if the left side and right side of "@" at least contain some character. There also may have been some restriction on the left side starting with a character. I think there was a validation check using regular expression in liferay already and it may just be a matter of copying it.
Vishal Panchal
RE: Client Side Web Form Validation Help
August 25, 2012 12:05 AM
Answer

Vishal Panchal

Rank: Expert

Posts: 264

Join Date: May 20, 2012

Recent Posts

Joshua Bertrand:
Thank you for the link. It was very helpful in understand the correct way to code a validation script. However, applying this to the Web Form portlet has still been unsuccessful and my form still submits when invalid characters are presented. Does anyone just have code that they use that you wouldn't mind providing?

Thank you.


Hi Joshua Bertrand,

please find the file attached .
it is a sample code what u exactly want.

Please let me know if any inputs required..!!emoticon

Thanks & Regards,
Vishal R. Panchal
Attachments: ClientSideJSValidation.html (1.0k)
Joshua Bertrand
RE: Client Side Web Form Validation Help
August 30, 2012 11:58 AM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

My form is still submitting with this code... here is a screen shot... is there anything I am doing wrong?
Attachment

Attachments: Screen Shot 2012-08-30 at 1.28.29 PM.png (38.6k)
João Gomes
RE: Client Side Web Form Validation Help
March 25, 2013 3:41 AM
Answer

João Gomes

Rank: New Member

Posts: 1

Join Date: March 12, 2013

Recent Posts

I have the exact same problem.
The validation script does not run.

How do i fix this, does it needs the script tags? Already tried and didnt work.
Help please.