Re: limiting a textfield to numbers
Re: limiting a textfield to numbers
- Subject: Re: limiting a textfield to numbers
- From: Timothy Worman <email@hidden>
- Date: Mon, 10 Nov 2014 16:49:46 -0800
I use Integer.parseInt - throws NumberFormatException if the String does not contain a parseable integer.
Tim
UCLA GSE&IS
> On Nov 7, 2014, at 9:04 PM, Theodore Petrosky <email@hidden> wrote:
>
> I’ve never written a validator before. Is this okay:
>
> public String validateJobNumber(String value) throws ValidationException {
>
> value = value.trim();
>
> boolean isNumber = true;
> endOfLoop:
> for (int i = 0; i < value.length(); i++) {
>
> if (Character.isDigit(value.charAt(i))) {
> isNumber = true;
> } else {
> isNumber = false;
> break endOfLoop;
> }
> }
>
> if (!isNumber) {
> throw new ValidationException("There can be only numbers in the Job Number field! (value was " + value +")");
> }
> return value;
> }
>
> It works, but is there some error that I am making that will bite me later?
>
> Ted
>
> On Nov 7, 2014, at 8:04 PM, Ramsey Gurley <email@hidden> wrote:
>
>> If you always only want to allow number characters, then implement a validateKey() method for that key on your EO. This is easier.
>>
>> public String validateJobNumber(String value)
>>
>> Alternately, you can provide a custom component that does the validation at the component level. For example, you have a bunch of old jobs that already have strings outside your defined range and you cannot validate at the EO. This prevents new jobs from being entered with job numbers like “00-103A” or something, but also won’t throw errors on old jobs unless the user tries to edit them using the component.
>>
>>
>> On Nov 7, 2014, at 5:51 PM, Theodore Petrosky <email@hidden> wrote:
>>
>>> How would you limit the characters typed into a WOTextField in a D2W app?
>>>
>>> I need a text field for a Job Number. It’s not really a number per se. Although I want to limit the characters typed to the number keys. So basically ascii 48 to 57 inclusive.
>>>
>>> Ted
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden