× Form Help

VALIDATING NON REQUIRED FIELDS

  • zaihasrul
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Karma: 1
  • Thank you received: 1

zaihasrul created the topic: VALIDATING NON REQUIRED FIELDS

Hi,

I need validation for non required field? I have to fields non required field text & phone.

The problem is if I add validation to these fields the form fails when submitted if the user has not filled those fields.

Can someone help?

Thanks
#238433
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2738
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: VALIDATING NON REQUIRED FIELDS

Hello,

What kind of validation did you write for this field?

In which way do you want to validate them?

What you want is doable, but requires a custom validation script which allows fields to be left empty.

Regards,

Mihaela
#238438
  • zaihasrul
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Karma: 1
  • Thank you received: 1

zaihasrul replied the topic: VALIDATING NON REQUIRED FIELDS

I am using this solution( crosstec.org/en/forums/1-forums/109604-v....html?start=6#158701 ) for field Phone and just change the element name & regex. When submit the form, the button submit turn to disable button. this is my script:
function ff_TelephoneNumber_validation()
{
  var idTelephoneNumber = ff_getElementByName('TelephoneNumber').value;
  
  if(idTelephoneNumber == '') {
  	return '';   
  	} 
  	else { 
  		var regex = /^[\+0-9]{2,5}\-[0-9]{7,8}(?:x.+)?$/;
  		if(!regex.test(idTelephoneNumber)){
  		return 'The phone number you entered isn't valid';
  	}
	return '';
  }
} // ff_TelephoneNumber_validation

Am I missing anywhere?
#238457
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2738
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: VALIDATING NON REQUIRED FIELDS

Hello,

I've been looking at the code and I realizes where is the mistake in your code.

Here is the working code:
function ff_TelephoneNumber_validation()
{
  var idTelephoneNumber = ff_getElementByName('TelephoneNumber').value;
  
  if(idTelephoneNumber == '') {
  	return '';   
  	} 
  	else { 
  		var regex = /^[\+0-9]{2,5}\-[0-9]{7,8}(?:x.+)?$/;
  		if(!regex.test(idTelephoneNumber)){
  		return 'The phone number you entered is not valid';
  	}
	return '';
  }
} // ff_TelephoneNumber_validation
The problem was in:
'The phone number you entered isn't valid'
You can either use this:
"The phone number you entered isn't valid"
or
'The phone number you entered is not valid'

Let me know whether after this change it is working as you want.

Regards,

Mihaela
#238465
The following user(s) said Thank You: zaihasrul
  • zaihasrul
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 76
  • Karma: 1
  • Thank you received: 1

zaihasrul replied the topic: VALIDATING NON REQUIRED FIELDS

Thanks. Its work :)
#238472
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2738
  • Karma: 93
  • Thank you received: 369

mihaela replied the topic: VALIDATING NON REQUIRED FIELDS

Hi again,

Great! I'm glad I've helped.

Regards,

Mihaela
#238473
Moderators: ForumSupporttomeperica
Time to create page: 0.069 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here