Beware of IsNumeric


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <%
  2. 'IsNumeric evaluates TRUE both integers and real numbers.
  3. 'You shouldn't rely on this function at all.
  4. 'Depending on your Locale ID (LCID) and what character is used
  5. 'as a decimal delimiter (, or .) it may mis-evaluate real numbers!
  6. 'For example"
  7.  
  8. Session.LCID=1049
  9. Response.Write(IsNumeric("10.5")) 'FALSE
  10. Response.Write(IsNumeric("10,5")) 'TRUE
  11. Response.Write(IsNumeric("10. 5")) 'FALSE
  12. Response.Write(IsNumeric("10, 5")) 'TRUE, assumes it's 10,5
  13.  
  14. Session.LCID=1033
  15. Response.Write(IsNumeric("10.5")) 'TRUE
  16. Response.Write(IsNumeric("10,5")) 'TRUE, assumes it's 105.00
  17. Response.Write(IsNumeric("10. 5")) 'FALSE
  18. Response.Write(IsNumeric("10, 5")) 'FALSE
  19.  
  20. 'It get's even worse when you try to evaluate Query String:
  21. 'http://www.website.com/page.asp?number=10&number=20
  22.  
  23. Session.LCID=1049
  24. IsNumeric(Request.QueryString("number")) 'TRUE
  25.  
  26. 'Evaluates TRUE because it returns IStringList with the following
  27. 'comma-delimited values "10, 20" and IsNumeric believes it's a real number
  28. %>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.