Validate a string is numeric, or integer

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Validate a string is numeric, or integer

Post by Marcus Tettmar » Thu Mar 12, 2009 5:33 pm

Using Easy Patterns in v11 to validate numeric data:

Code: Select all

//IsNumeric?  
Let>data=154.3  
RegEx>[lineStart][oneOrMore number or "."][lineEnd],data,1,matches,num_matches,0  
If>num_matches>0  
  //string IS numeric  
Endif  

//IsInteger?
Let>data=154
RegEx>[lineStart][oneOrMore number][lineEnd],data,1,matches,num_matches,0
If>num_matches>0
  //string IS integer
Endif
Using VBScript:

Code: Select all

//IsNumeric?  
Let>data=154.3  
RegEx>[lineStart][oneOrMore number or "."][lineEnd],data,1,matches,num_matches,0  
If>num_matches>0  
  //string IS numeric  
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts