Pardot form validation regex - pardot

I've created a custom form field for Canadian Postal code. Is there a way i can validate the format using RegEx? I can make it required, but I need more than that.

Related

Angular2 dynamically update validation rules

In Angular2 I need to modify validation rules dynamically.On the selection of a value from a dropdown validation rules will be fetched from the database and they would be like
{filedName : FirstName, required : 1}.
Currenlty I'm suing template driven form validation but after searching a bit I have realised that I would have to use model driven approach. Any ideas on how to do that?
Edit
Answer by JayChase to the above mentioned question seems the right one in my scenario. But I have couple of queries.I can remove all validation rules by passing null to setValidators but how can I just remove required field validation.And is it possible for me to modify validation rules in template driven approach.
Update
I'm able to update validation rules by following JayChase's answer.I did not use async validation as it would have costed me too much server calls. So now the issue is how to update just the required field validation rule.Right now I'm removing all validations from the control.
form.controls["fieldName"].setValidators(null)
Any help on that would be much appreciated.

I would like to define a component as optionally required (based on another field's value)

I built two custom components using built-in CQ components. The components' JSP's, along with some custom javascript, have a line like below in order to leverage the built-in components (and their formatting, labels, etc.).
<cq:include path="." resourceType="foundation/components/form/dropdown" />
I have one each of my custom dropdown components on a form. I can mark field A and field B as both being required in their respective components' editor dialog. I can provide required messages so that when either field is blank and the form is submitted, I get a message that the fields are required (with my custom messages). However, what I really want to do is hide or disable field B based on the value supplied in field A. I'm handling this manually via jQuery. However, this of course presents a problem on validation. I want field B to be NOT required when it is hidden/disabled and for it to be required when it is enabled/visible. Since the showing/hiding is done client-side, the server-side validation has know knowledge of the change and still expect a value to be provided for field B.
I'm been trying to poke around in the CQ Widgets API to find if there is something I can do on the client side to set/unset the required property so that when the form gets posted it is handled correctly. I'm guessing that there isn't since the validation seems to be happening on post instead of client-side.
Any ideas/thoughts/options?
It turns out that the link from my comment gave me the idea that I can have custom server-side validation for my form, I just wasn't sure how to connect it to the field. It turns out that all I had to do was create a servervalidation.jsp file in my "B" component. CQ will see the servervalidation.jsp and automatically invoke it for my custom component.
I was then able to examine the submitted value of field "A" (by getting the parameter from the request object) and doing some other custom logic for my needs.
I was then able to optionally do this:
FieldDescription field = FieldHelper.getConstraintFieldDescription(slingRequest);
FieldHelper.checkRequired(slingRequest, field);

validation.xml change mask value on condition

I am working on struts server side validation(version 1.2). I have used validwhen several times. I have 2 textboxes that submit to server. text1(value comes here from a drop down selection) can have name or id. text 2 holds its value. I have to write validation on text2. Is there a way where i can change mask var-value in validwhen ? i.e if text1 value is name then text2's mask should be a regex for name(alphanumeric and space). if text1 value is id then text2's mask should be a regex for id(only numbers). Is there a way this can be achieved? I don't think we can write 2 different validation on same field.
thanks,
IMO validation like that belongs on the Java side.
You can either wrap it up in a custom validator if it will be used across the app, or as part of the form's validation method, where you could also combine it with standard XML validation.

Jquery validator method not working if used multiple times in a form

we are using a javascript form where a enduser has to enter phonenumber and promo code apart from other details. All the fields in the form are mandatory.
I am using validator.add(method) to validate phonenumber using regex.
Also using an another validator.add(method) to validate the promo code
But am able to use only one validator method. If am using multiple i.e., more than one, then the validation is not working.
Is the jquery validator method restricted to use only once in a form.
Please suggest me a solution for this.
You can use an OnSubmit function for the form and validate all the data there, you can also write several functions and use them in the main onsubmit function.

Using the Codeigniter form validation library, how can I ensure at least one letter is entered?

I am using Codeigniter form validation. In my registration form the Username field allows only numbers like 123456. I don't want this to happen.
My validation rule is as follows
'rules'=>'trim|required|alpha_numeric|min_length[6]|xss_clean'
I want to prevent users entering just numeric strings. Alpha numeric strings are fine, alpha strings are fine, but purely numeric ones are not.
To allow only letters
Add alpha to your rules and remove alpha_numeric from your rules
You can use this page as a point of reference for built in validation rules.
Edit:
Since you've clarified now.
To achieve this, there's no built in validation rule. You will need to extend the Form_validation library by creating a libraries/MY_Form_validation.php file. See this manual page on how to extend libraries.
In this file, create the following function
function at_least_one_letter($string) {
return preg_match('#[a-zA-Z]#', $string);
}
Then you can add the validation rule at_least_one_letter to your rules.
According to the codeigniter user manual :
You can also use any native PHP functions that permit one parameter.
I think in this case is_int could be used as your validation rule.
So, for instance:
'rules'=>'trim|required|is_int|min_length[6]|xss_clean',

Resources