Link to home
Start Free TrialLog in
Avatar of prenexus
prenexus

asked on

Validating text input into a numeic field

Hello,

Ive got a validation question for you.

On a form I want to validate that the value entered into a numeric field is actually a numeric.

Ive looked at the input validation section but that only seems to check on a save. I need to check as soon as someone leaves the field.

So...what Ive done is put some script into the Exiting event.

Ive got this...

Sub Exiting(Source As Field)
     
     Dim ws As  New NotesUIWorkspace
     Dim doc As NotesDocument
     
     Set uidoc = ws.CurrentDocument
     Set doc = uidoc.document
     
     If (Isnumeric(doc.annualdays(0)) = True) Then
          End
     Else
          Msgbox "You must enter a numeric value for this field",48,"Numeric Field Error"
     End If
End Sub


Now this works ok if you have a space or number in the field, but if you put a character in - 'a' for instance, then the script generates an error to the effect of "Variant does not contain a container"

Obviously this isnt an ideal error message for users...

Does anyone know how I can accomplish this?

Many thanks,

Mat
Avatar of HemanthaKumar
HemanthaKumar

Hi Mat

The numeric fields always validate for numeric values, this is the default behavour, if it is a text value  then it will prompt u with the error message.

For that you must enable "automatically refresh field" in the form properties. If u do so then user is prompted with error msg saying that the value is incorrect.

Good luck
~Hemanth

ASKER CERTIFIED SOLUTION
Avatar of Antonysingh
Antonysingh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prenexus

ASKER

HemanthaKumar,

Thanks for the answer - and while it does provide a solution its not really what I was looking for.

Thanks,

Mat
Antony,

Thanks for the comment! Thats exactly what I was looking for.
Whats more youve shown me a way to highlight the field that was causing the trouble as well.

Mat
That's OK.

May be I don't know the whole picture, and Antony got it.

~Hemanth