I know that using jquery validator we can allow specific characters in a textbox while validating form.
Is it possible that jquery validator should not allow specific array of strings. We can't write plenty of lines to check whether equal or not.
Thanks in advance:-)
Related
I have the following problem:
I have a form where a user can opt to toggle a switch (Yes/No).
If they select Yes, I hide a couple of fields on my template (because they will now automatically be calculated).
The catch is that now, a set of different fields are required to not be empty for the successful submission.
The first fields need not be optional after the switch is clicked (since they are merely hidden but still submitted), but the second set of fields must be non-empty.
Is there a simple way to get this dynamic validation behaviour using Symfony's sfValidator classes, or should I simply hack together a solution using jQuery?
This sounds like a perfect case for the Callback constraint that already exists in Symfony. To quote the linked doc:
The purpose of the Callback constraint is to create completely custom validation rules and to assign any validation errors to specific fields on your object. If you're using validation with forms, this means that you can make these custom errors display next to a specific field, instead of simply at the top of your form.
This solves the backend, you still need to watch out for the required attributes of your fields so HTML5 validation can work properly.
Is there a way to block or restrict special characters from input fields with jquery-validation?
For example, I would like to only authorize those characters [0-9\/]*.
I've read the whole documentation but I haven't found anything. So instead I've to write special codes for this which is not a good choice for the code.
I've seen that other javascript plugin validation can do that like Parsley by using a requirementType. But I don't really want to change the plugin to another cause I already know how to use it now.
Using jQuery validation, you can use this method (http://jqueryvalidation.org/jQuery.validator.addMethod) to add a validator that uses JavScript regex matching to return true or false if the input matches your pattern. This is a very easy way to integrate with the library you're using.
If you want to literally prevent the user from typing characters other than those, you need to attach an event handler to the inputs and block those characters on the keyDown event.
Either way, the matching logic is the same.
i am creating a sign up form in which there are 7 required fields, i want to validate those required fields using javascript.
i tried if-else block but its troublesome and confusing, is there any other way to do those required field validation in javascript, without using jQuery validation library?
Thanks.
If you are using html5 you may want to take a look into the newer input tag attributes.
http://www.w3schools.com/html5/att_input_required.asp
see http://www.w3schools.com/js/js_form_validation.asp
and http://php.net/manual/en/filter.examples.validation.php
both sites have form validation made easy, PHP's is built-in
You can use the pattern attribute which is a regular expression that is checked against the content of the field to determine whether or not the field is valid. Also, to make sure that the field is not empty, you can use the required attribute.
I'd like to get some input from the user:
keywords = prompt("Input keywords separated by commas", "");
I have many various strings stored in an SQLite database that could suggest the user what to type.
Let's say you have an array or list of these strings. How would you code this hinting in Javascript? Are there some functions or code snippets for this functionality?
I'd like it to work similarly as here. When you start typing you get hint with possibilities. There is only one disadvantage, that you can't input more strings separated by commas. Here is this feature working with more strings.
Is prompt() function suitable for this purpose? You can use another way of getting user input.
Thank you
You cannot tweak the native prompt() javascript method.
I know you did not tag with jQuery but would be way easier to use a library to implement such a behavior.
You'll have to build your own dialog system using maybe jQuery UI Dialogs. They have an option to make it modal so the UI is blocked until the dialog is closed.
jQuery UI Dialog will not block javascript execution though like prompt does. You might need to be able to execute code when the dialog is closed. This answer show a way to implement that easily.
Finally, the jQuery UI Autocomplete provides an example on how to use it for multiple values in the same input. They use a comma-separator but I guess you could modify the example to work with whitespaces: jQuery UIAutocomplete Multiple Values
You can't really use any custom functionality with prompt().
You'd be better off creating an <input type="text"/> and hooking the whole thing up to a button, making the data get submitted whenever a use clicks it, or presses enter. Then code it to fetch an autosugges value whenever the user types in a new character.
You should take a look at jQuery UI's autocomplete component (it works with multiple strings as an input as well). You would also need to set up a server-side script that will take a possibly incomplete string as an input and output a possible list of matches back to the browser.
I want a class in JavaScript through which I can validate all the Input Boxes on a form. I just want to supply the form name and it must validate the input boxes there in.
Is there any class or something other through which I can achieve this?
Have you looked at the validator plugin?
http://docs.jquery.com/Plugins/Validation
If you don't want to use JQuery I described an alternative library in an earlier post
What JavaScript library to use for client-side form checking?
That allows you to just add attributes like REQUIRED or DATE to an <INPUT> tag.
It's a bit old-hat now, but we are still using it in production :)