Disallow negative numbers in h:inputText - validation

I want to apply validation if -ve value is entered. I could do that using below tags and attributes:
<h:inputText id="MyPrice" validatorMessage="negatieve prijs niet toegestaan">
<f:convertNumber type="number"
groupingUsed="true"
locale="nl_NL"
maxFractionDigits="2"
minFractionDigits="2"/>
<f:validateLongRange minimum="0"/>
<h:inputText>
<rich:message for="MyPrice"/>
Using this I can successfully validate -ve and +ve values with below inputs:
Went right for: [I'm following Netherlands number system where ',' is treated as '.' eg to write 0.55 we need to write 0,55) that is done by me using <f:convertNumber>.
100
10.25
10,98
-100
-10.25
-10,98
0.55
But when I entered -0,55, validation didn't work. Kindly provide solution to validate when I'm entering -ve value that starts with -0.xx.

Your validator is not correct - price is not Long. Change it to
<f:validateDoubleRange minimum="0" />

Related

How to use fmt:formatNumber with 2 decimal

I have value 6666666666666666.6 and using fmt:formatNumber to format on jsp(jstl)
<fmt:formatNumber type="NUMBER"
minFractionDigits="2"
maxFractionDigits="2"
value="6666666666666666.6"/>
Display result: 6,666,666,666,666,667.00
Result expect: 6,666,666,666,666,666.60
Please share me a solution.
Thanks
Have you tried changing the type from number into currency?
<fmt:formatNumber type="CURRENCY"
minFractionDigits="2"
maxFractionDigits="2"
value="6666666666666666.6"/>
<c:set var="N-15-digits" value=${666,666,666,666,666.6}/>
<c:set var="N-16-digits" value=${6,666,666,666,666,666.6}/>
<fmt:formatNumber value="${N-(0.1-(N%0.1))%0.1}" type="number" minFractionDigits="2"/>
This solution could always show without rounding If input value under 16 digit, result comparison is on following.
N-15-digits would show
666,666,666,666,666.60
N-16-digits would show
6,666,666,666,666,667.00

Set min value for numeric textbox in Kendo ui template

I need to prevent negative values in Kendo numeric textbox template as below:
<input type="text" data-type="number" data-format="n0" name="SnoozeLength" data-bind="value:snoozeLength" data-role="numerictextbox" />
is there any attributes which i can use line "min-value= 0"
Try with the following:
http://docs.telerik.com/kendo-ui/api/web/numerictextbox#configuration-min
You can specify min configuration for your numerictextbox.
Best Regards,

radnumeric textbox allows ony 16 numbers

I have the following rad numeric textbox.
> <telerik:RadNumericTextBox ID="numTxtIMEI" runat="server"
> MaxLength="20" MinValue="0" Visible="false"
> maxvalue="99999999999999999999" AutoCompleteType="Disabled">
> <NumberFormat GroupSeparator="" DecimalDigits="0" /> <ClientEvents
> OnKeyPress="preventDecimalSeparator" /> </telerik:RadNumericTextBox>
Inspite of setting maxlength and maxvalue to allow 20 numbers into the textbox, it allows only 16numbers . when i type 17th number, it automatically turns to zero. what should i do to allow this numeric textbox to allow 20numbers?
"Telerik RadNumericTextBox control does not support maximum/minimum value more/less than +/- 2^46
Setting the MaxValue property more than 2^46 may cause abnormalities in the RadNumericTextBox behavior."
Quoted from a Telerik forum posting. I have linked it below. It does give an option on how to do a larger number, but I have not tested that myself.
http://www.telerik.com/community/forums/aspnet/input/change-max-value-of-radnumerictextbox.aspx

Validating input type number in html5

I want to restrict entry of input onto a field of type number such that input cannot be outside range of min-max specified in the html.
input type = "number" min = "1" max = "5"
Is there a way of outputting the number field without the text box and i would rather not use
"input type = range"
as slider does not show value currently selected
Please help.
Thanks.
Based on what you said, I suggest using a simple input text field and check it's value validity on submission via JavaScript (as #Kush mentions above). You could also check it as the user types, or moves focus away from that field.
<form>
Only 1 to 100 <input type="text" name="number" pattern="\d{1,2}(?!\d)|100" title="one to hundreed only">
<input type="submit">
</form>

Custom ValidationTextBox in Dojo

I am new to Dojo programming and trying to create a ValidationTextBox for username input. I would like to have three criteria: 1. users can only input alphanumeric characters and 2. minimum length of a username is 6 character 3. this field is required
So far my input looks like:
<input name="username"
type="text"
id="username"
class="reqd1"
required="true"
trim="true"
lowercase="true"
promptMessage="Username"
invalidMessage="Please only enter alphanumeric characters."
maxlength="12"
regExp="[\w]+"
intermediateChanges="false"
dojoType="dijit.form.ValidationTextBox" />
I have three questions:
1. how I can check for the the minimum character of the username field?
2. Is there a way to change the invalidMessage programatically?
3. How I can check the length of the username field without using regEx?
regExp="\w{6,12}"
dijit.byId("username").set("invalidMessage", "new message");
I think regExp is the best way in your case

Resources