Jump to content

Invalid Characters

- - - - -

  • Please log in to reply
1 reply to this topic

#1
jgraham95

jgraham95

    Newbie

  • Members
  • Pip
  • 3 posts
Hi there im looking for a way to recognise invalid characters in my asp.net page.

What im doing is creating a temperature guage where a user inputs a temperature and depending on the temp it will display a input which ive done. Ive acieved this with a textbox and coverting it to int32. however if i type in letters or £$%^& it crashes. Im looking for some help on how to resolve this with either a msgbox or a label to say i need to inpuit valid characters. However i need - to be valid for minus temperatures.

Cheers

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You can add a validator from the toolbox to the textbox / textfield.
In this case, i think you got 3 options: a range validator(easiest to use,, yet you must give a min and max value). a regularexpressionvalidator (google for "regular expression integer" or "regex integer"), or a customvalidator (you'll have to write your own validation in the code-behind.)
These are client-side validations. Meaning the page doesn't need to refresh or load again, to validate the input. (not sure about the custom one, but i suppose it's client side too:confused:)

As for security reasons, you should think that all the input you get from a client can always be corrupt. So I suggest that when you parse user input to integers you use the tryparse method(Int32.TryParse Method (String, Int32) (System)) which returns a boolean, and if false you can send the user to an error page or set a label's text to inform the user he's entered wrong input.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users