Solved

VB Script IsNumeric Function and the dollar sign

Posted on 2010-09-23
8
1,739 Views
Last Modified: 2012-05-10
Hi - I have a classic ASP page that uses VBScript and I need some help.  

I have a form that allows a user to enter a budget amount.  I want to insure the value the user enter EXCLUDES the dollar sign ($) and the comma (,).  

Example:

$10,500.00 (False)

10500.00 (True)

I wrote this to test the value entered...

If NOT IsNumeric(strBudget) THEN
  ' message
End If

.... but IsNumeric allows the dollar sign and comma and returns True.  

Is there another function that I could use to test the value entered?  I want to make sure the user isn't entering a dollar sign or a comma.

Thanks.
0
Comment
Question by:cdemott33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33744645
You may want to use Regular Expressions, and test on this pattern:^\d\.?\d*$
0
 
LVL 28

Expert Comment

by:strickdd
ID: 33744659
You will have to check for the existence of the "$" and "," on top of the IsNumeric check. Use the InStr function to do this: http://www.w3schools.com/VBscript/func_instr.asp
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33744663
For more about using RegExp to validate entries in ASP:http://www.4guysfromrolla.com/webtech/120400-1.shtml
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:cdemott33
ID: 33744678
matthewspatrick - Can you provide an example of how I could do this?
0
 
LVL 13

Expert Comment

by:samic400
ID: 33744684
If you could use javascript -

script would be this -
function validateNumberField (objEvent)
        {
        var iKeyCode;
            iKeyCode = objEvent.charCode ? objEvent.charCode : objEvent.keyCode;
      if(iKeyCode>=48 && iKeyCode<=57) return true;
        if (iKeyCode == 8) return true;
        return false;
      }

then your code would have something like this:
<input type="text" size=1 name="month" id="month" onKeyPress="return validateNumberField(event);">

and only allow numbers.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33744685
>>You will have to check for the existence of the "$" and "," on top of the IsNumeric checkAnd that's not all.  For example, these return true as well:IsNumeric(" 1234")IsNumeric("1234 ")IsNumeric(" 1234 ")RegExp is looking better and better :)
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33744875
For an example, see:http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_21591244.htmlNote that you should use the pattern string I supplied in my first comment...
0
 

Author Closing Comment

by:cdemott33
ID: 33744911
Thank you.  Using a regexp match worked perfectly.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question