I'm working on a html form, and I like to know if there is a tool or way to restrict the user to some rules in inputs, i.e.:
-Don't allow the user to put more than 2 digits after the dot
-Don't allow the user to put more than 1 dot
I was thinking on regular expressions but how to apply that live.
Thank you.
You can run a form validation process with JavaScript. Use HTML DOM to get all the input fields, then use string manipulation to search it's "value" attribute for characters.
document.getElementById() and similar methods can retrieve different elements on the page. After the getElement method you used to find the input field, type ".value" and then it should return whatever is in that field. Then run that through something like data.includes() or similar to check for certain characters.
Related
As I tried to look around for an answer, And I couldn't find one, although it may be very simple.
I am doing an HTML form, with a selectelement. where the value is supposed to be a number, (going with a POST method straight into the Data-Base).
I am getting an error as the DataBase complaints that the value is text, and it has to be an integer.
Now, my question is, is it possible to define value="number" as we can do with an input element?
Any kind of data submitted from a form is going to be text (if we ignore file inputs in multipart forms at least). This includes <input type="number"> (which just stops the text from including non-number characters).
If you want to make sure that the data is a number then perform type conversion on the string when it gets to the server.
In my APEX application I have some calculation routine implemented in Javascript. The input is taken from multiple Text Fields. I want the calculation routine to work each time any of those Text Fields has been changed. Using Dynamic actions, how can I share this Javascript function among multiple Text Field change actions? Preferably avoiding any CSS modifications.
You can select multiple page items when specifying your single dynamic action to fire on change. They are comma separated in the Item(s) field (clue is in the name).
Also, as mentioned in the comments above, you could use a CSS class to group your items. As for whether this is a bad thing, check out this question.
Best practice: class or data attribute as identifier
Personally, I feel comfortable using classes to allow for easy jQuery selectors and it is both very common and natively supported in APEX.
I have a more or less complex SPA with ~40 text input fields. Those input elements are not bundled by a <form>, but they are separated into categories. If a user submits, i would like to trigger a validation function.
My first approach was writing two directives, one for string input and one for numeric values, which would add an attribute to every invalid element, then using a validate() function which would look up every input field in order to check whether or not it has said attribute.
I stumbled over multiple issues, including the fact that this was a jQuery like solution to the problem.
How could i accomplish this in a more convenient way?
One of the ways I have been handling form validation when things are not inside of a form is by using ng-pattern. With ng-pattern you can either do direct regex there, or link to an expression to run a set of validations for you.
It would look something like this.
<input type="text" ng-pattern="Put your Regex Here or an Expression">
The angular docs for ng-pattern are pretty sparse, so good luck.
This approach may not be what you are looking for since it evaluates only one input at a time, but I hope this helps.
I have seen many ways to validate these dates, but I don't actually know which is the best way to validating the two text boxes.
Once I click on my submit button, the onsubmit = check() will check the dates if they are correct or not.
The best way to handle validation in Javascript is with regular expressions. Check out examples here
If you need to manipulate the date, i.e. if you want to convert it through code then you need to split the string up using the Split function and then combine it in the correct order again. Check out example here.
I have a script in a web application of mine which forces users to type only numbers into certain text fields. However, when the appropriate text field is selected, the script blocks ANY keyboard input other than number keys and tab. I don't want to limit the user from being able to use their browser's or my app's keyboard shortcuts just because they are typing in a numerical field. (Also, I'd rather not just validate the field instead of preventing number input, my app updates the page based on the numerical input live, so it wouldn't be as nice.)
Can someone please help write/find a little script for me? A simple variation of these numbers-only scripts that can be overrided when a modifier key is pressed is enough (and I guess the overrided character would have to be deleted, too).
I'm not going to write a script for you, but I'll give you some pseudo-pseudo-code:
input = input.replace(/\D/, '');
Try YAV, Javascript validator library.
I think you need mask feature.
Look at field Custom: from this example
http://yav.sourceforge.net/en/example_7.html