I have a textfield in which I want to restrict user to enter only valid number with 14 digit before .(dot) and 4 digit after .(dot).
I have tried it using :
<mx:TextInput id="txtValue1" restrict="[0-9]*\.?[0-9]" maxChars="19"/>
Its not working for restriction 4 digit after .(dot).
A more common way would be to use a NumberValidator, and set the precision attribute of the validator to 4. Also, set the maxValue of the NumberValidator to whatever suits, then set the source of the NumberValidator to the textInput id. That should work I'd say, and it will also allow you to set the error fields of the validator which will pop up beside the textInput if incorrect number is entered
you can view and download a code (this works!) in my public repository from this LINK.
Basically, i created a class (NumberInput) based on TextInput class from Adobe, the diferrence in both classes was the textFieldChanged method, i add a call here to myFormat function(). This function does what you're needing.
Be careful with this class, do not use it as the final solution but I will anyway to find what you need. Check the SWF called NumberInputTest.swf, source code is in src\NumberInput.as.
I hope this help you. Sorry for my english :D.
Related
I'm developing an desktop application with java, right now I'm at the point of registering person data. One of the fields of the person form is "DocumentTextField" which holds the Identification Document and Number, that's why I tried to use a JFormattedTextField mask, to help user with the format to this field.
Basically, I just used the AbstracFormatterFactory to create the mask:
Mask = UU - ########## to get something like (PP-0123456789)
It does work perfecly on the fly, the user just type "pp0123456789" and the mask become this to "PP-0123456789" the point is the numbers length, as you can see on my mask, i declare 10 numbers (##########) but in fact, It could be lower than 10 numbers or even Higher. It does only work with 10 numbers, if user type lower than 10 numbers, the JFormattedTextField resset to empty, the same thing happen if user type more than 10 numbers.
is there any way to declare the range (numbers length) of this? some document are just 5 numbers (PP-01234).
Thank you so much in advance by reading this and trying to help.
I assume you're using Java 8 for your development. Are you seeing any kind of ParseException?
As per the documentation of the component: https://docs.oracle.com/javase/8/docs/api/javax/swing/text/MaskFormatter.html
When initially formatting a value if the length of the string is less than the length of the mask, two things can happen. Either the placeholder string will be used, or the placeholder character will be used. Precedence is given to the placeholder string.
According to the example:
MaskFormatter formatter = new MaskFormatter("###-####");
formatter.setPlaceholderCharacter('_');
setPlaceHolderCharacter method can help you with your problem.
I've tried Juzzy in Java. After defining the membership functions, antecedents, consequences and my rule base, I tried to print the output of a sample input which I entered. I saw that the only output can be the defuzzication number (type of double). But I need the class of the rule which fires with a sample input, not the defuzzication number. Anyone knows about the appropriate function for my problem?
I think
rulebase.evaluate(0).get(tip)
Let's assume this situation.
I have length label. Sometimes I want it to show me the message Length must be lower than 5!, but other time it should show Length must be value between 2 and 5!. It should depend on number of arguments I pass to this.
Could it be done without using second label, for instance Length?
It can be done without different values in your property file.
For e.g. you could have your label as such:
my.label=Length must be lower than 5!,Length must be value between 2 and 5!
But this is NOT recommended. You need to split it based on your separator, comma in this case, and handle that logic yourself.
The clean solution would be:
my.label.error.maxsize=Length must be lower than 5!
my.label.error.size=Length must be between 2 and 5!
And of course the value maxsize or size can be set programatically.
EDIT:
The java implementation depends a lot on the framework used to load values from property files.
is anybody know how to format String with mask using jstl tags? let say you want to show confidential credit card number in list and you just want to show first 4 digit and else will be masked with * something like :
1234-****-****-****
I don't think there is anything out of the box to do this. The fmt namespaced tags are about formatting numbers and dates and i18n stuff, but nothing about string formatting. If you don't want to be doing this in your presentation layer with scriptlets or function invocations, you might want to consider adding another model property for the obfuscated CC number that way you can do the formatting in Java where it will be much easier.
In my web app,I need to get a user entered number and process it in the controller.I need to make sure that the number is at least 14 digits in length.If the user enters 12 digits and then presses 'space' twice ,the validation should catch it.
I coded it like this
public static void processNumber(#Required #MinSize(value=14,message="min size is 14") String inputNumber){
if(validation.hasErrors()) {
params.flash();
validation.keep();
...
}
}
However ,this doesn't work as I expected..Looks like ,I need to trim the input before it reaches the controller method.
Can someone suggest how to do this?
p.s:
More complex cases will be input like
'11 2233444444'
'1122334ad44444' etc,is there any validation to make sure that the input is a number and does not contain any alphabetic characters?
I don't think a custom binder is going to give you what you are looking for, as you are not trying to modify the way the data is bound, but to validate what is in there. Therefore, I think what you are looking for is a custom validator.
See here for more information - http://www.playframework.org/documentation/1.2/validation#custom
But effectively, you can just use the #CheckWith annotation to specify which validator to use, and then in your validator, you can check that your trimmed string, contains no spaces, and no alpha characters etc.
Note, that the validator will not modify your input, so if you want to ignore trimmed data, then this will continue to stay in your data, so you can therefore modify (trim) it after it is validated, or you could do it using the custom binder as discussed in the other answer.
Please check if that could help you on what you want to do link
I hope it helped.
If you want to have a numeric value with at least 14 digits, one option would be:
public static void processNumber(#Required #Min(10000000000000) Long inputNumber)
Problems with this method:
Maximum allowed number would be 9223372036854775807l
It won't allow numbers starting with "0".
Some more options:
public static void processNumber(
#Required #MinSize(value=14,message="min size is 14") String inputNumber){
validation.isTrue("inputNumber", !inputNumber.contains(" "));
if(validation.hasErrors()) {
Or even better:
public static void processNumber(
#Required #MinSize(value=14,message="min size is 14") String inputNumber){
for(int i=0;i<inputNumber.length();i++) {
validation.isTrue("inputNumber", Character.isDigit(inputNumber.charAt(i)))
if(validation.hasErrors()) {