{"id":515,"date":"2009-03-12T17:14:29","date_gmt":"2009-03-12T17:14:29","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/?p=515"},"modified":"2009-03-12T17:14:29","modified_gmt":"2009-03-12T17:14:29","slug":"isnumeric-more-fun-with-easy-patterns","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2009\/03\/12\/isnumeric-more-fun-with-easy-patterns\/","title":{"rendered":"IsNumeric: More fun with Easy Patterns"},"content":{"rendered":"<p>VBScript has a function called IsNumeric, but as discussed in <a href=\"http:\/\/www.mjtnet.com\/usergroup\/viewtopic.php?t=3552\">this forum post<\/a> VBScript numbers can contain the letter &#8216;E&#8217; (and it would seem &#8216;D&#8217; too).  These are valid numbers as far as VBScript is concerned but in the real world we usually don&#8217;t care for them.  Numbers may also be floats.  So in the forum post we came up with the following VBScript functions for IsNumber and IsInteger:<\/p>\n<pre name=\"code\" class=\"macroscript\">VBSTART\r\nFunction IsNumber(var)\r\n  IsNumber = (LCase(var) = UCase(var)) and isNumeric(var)\r\nEnd Function\r\n\r\nFunction IsInteger(var)\r\n  IsInteger = IsNumber(var) and (InStr(var,\".\") = 0)\r\nEnd Function\r\nVBEND<\/pre>\n<p>Now we have Easy Patterns I thought I&#8217;d show you another neat way to validate that a string is numeric:<\/p>\n<pre name=\"code\" class=\"macroscript\">\/\/IsNumeric?\r\nLet>data=154.3\r\nRegEx>[lineStart][oneOrMore number or \".\"][lineEnd],data,1,matches,num_matches,0\r\nIf>num_matches>0\r\n  \/\/string IS numeric\r\nEndif<\/pre>\n<p>If you just want to check the string is integer, change it to:<\/p>\n<pre name=\"code\" class=\"macroscript\">\/\/IsInteger?\r\nLet>data=154\r\nRegEx>[lineStart][oneOrMore number][lineEnd],data,1,matches,num_matches,0\r\nIf>num_matches>0\r\n  \/\/string IS integer\r\nEndif<\/pre>\n<p>If we want to see if a string merely <em>contains<\/em> a number we can do:<\/p>\n<pre name=\"code\" class=\"macroscript\">\/\/Contains a number?\r\nLet>data=fred 224 sally 4\r\nRegEx>[oneOrMore number],data,1,matches,num_matches,0\r\nIf>num_matches>0\r\n  \/\/string CONTAINS number\r\nEndif<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>VBScript has a function called IsNumeric, but as discussed in this forum post VBScript numbers can contain the letter &#8216;E&#8217; (and it would seem &#8216;D&#8217; too). These are valid numbers as far as VBScript is concerned but in the real world we usually don&#8217;t care for them. Numbers may also be floats. So in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/515"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=515"}],"version-history":[{"count":3,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/515\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/515\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}