View Full Version : Numeric Validation
Baleric
05-25-2006, 01:37 AM
hey guys, i desperately need to know how to make a field validator that only allow you to type in numbers into a feild. so if someone types in letters then a message pops up saying "please enter numbers" or something along those lines,
ive tryed using the dreamweaver validator but because i wrote my own recordset it doesnt work...
please help.
cheers.
baleric
ghell
05-25-2006, 01:18 PM
If you wish a little messagebox to appear you would have to use javascript (or ASP.NET's validator controls but this is the ASP section not the ASP.NET section). The best method of doing this would probably be to put a javascript function on an event associated with the input field that returned false when someone entered a non number (returning false should just make it do nothing when they enter an invalid number), then use asp's IsNumeric() to make absoultely sure its a number when the page is processed (incase they had javascript disabled or whatever) but vbs is dynamically typed so IsNumeric("") returns true so watch out for that.
degsy
05-25-2006, 03:59 PM
The Dreamweaver validation is Javascript and only requires a named textfield within a form.
It shouldn't matter if you wrote your own ASP code or not.
Baleric
05-26-2006, 03:02 AM
The Dreamweaver validation is Javascript and only requires a named textfield within a form.
It shouldn't matter if you wrote your own ASP code or not.
but i am using me own repeat region not the DreamWeaver one, so when the form repeats itself it doesnt work properly.
Baleric
05-26-2006, 03:06 AM
If you wish a little messagebox to appear you would have to use javascript (or ASP.NET's validator controls but this is the ASP section not the ASP.NET section). The best method of doing this would probably be to put a javascript function on an event associated with the input field that returned false when someone entered a non number (returning false should just make it do nothing when they enter an invalid number), then use asp's IsNumeric() to make absoultely sure its a number when the page is processed (incase they had javascript disabled or whatever) but vbs is dynamically typed so IsNumeric("") returns true so watch out for that.
thanks ghell, i used this code.
<% If IsNumeric(request.form("ammount")) = false Then response.Redirect("error.asp?err=1") %>
worked great.
cheers.
baleric
ghell
05-26-2006, 04:18 PM
No problem just remember that a blank entry also comes out as true so the number "" would not be caught by it, you may wish to say
If Request.Form("ammount") = "" OR IsNumeric(Request.Form("ammount")) = False Then ...
Edit: i also need to do the compulsary pointing out that dreamweaver imo is a piece of bloated crap and the js it produces is disgusting and rarely works as intended ^^ text editors (and command line compilers) for the win :D
degsy
05-31-2006, 03:33 PM
Dreamweaver works fine if you know how to use it and what it's limitations are.
It definately is the best code editor I have used. The syntax highlighting and code blocks are a must for a programmer.
This means just the editor, not the design view.
Added to this is the file manager and find & replace.
The amount of problems you see with string syntax when the user hasn't had the benefit of syntax highlighting is unreal.
ghell
05-31-2006, 05:09 PM
These features can be found in hundreds of more lightweight editors anyway though such as crimson editor(site seems to be down at the moment so i cant link you, it was on www.crimsoneditor.com anad the domain hasn't expired.. there is a wikipedia article on it here though http://en.wikipedia.org/wiki/Crimson_Editor and it says that an open source alternative known as emeral editor has replaced it so i will check that out now..) which has syntax highlighting for hundreds of languages (hell it even has ms batch!.. and you can write you syntax files), autoindentation, tabbed editing, regex global find and replace, encoding, unix/dos/mac detection for line ends, recordable macros, bracket/block selection, some funny thing where you press ctrl+return and it does maths for you or something.. i havent quite worked that one out yet.., inline ftp, etc.. there are hundreds of similar editors out there that are free so why do people chose a heavyweight alternative which (on my laptop) takes a while to load and in some cases isnt even as powerful!
i know how to use dreamweaver its the thousands of people that dont that annoy me (and thus i see 200 lines of MM_blahblah() all over the place for a simple rollover.. or NAVIGATION BUTTON which can just be a hyperlink!)
My main quarrel with dreamweaver is the wysiwyg designer rather than the text editor.
Baleric
06-01-2006, 02:20 AM
i started off using dreamweaver for everything, including login scripts and user authentication, then i relised that everytime you genereate a login script or page validation script it always uses the same session MM_username or sumthing, then i went looking for other dreamweaver made websites and could get into all the admin pages by creating the same session on another page.
it was great for a while then it happened to my web site :( lol,
thats when i started making my own stuff.
dreamweaver is great for people new to .asp because u can see all the power of asp by clicking buttons instead of learning the code right away, it inspires you to learn more!
thanks for helping me with my problem by the way
cheers,
baleric
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.