Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
This is the function isnum from maincore:

// Validate numeric input
function isnum($value, $decimal=false) {
   if (!is_array($value)) {
      if($decimal==true) return (preg_match("/^[0-9]+(\.{0,1})[0-9]*$/", $value));
      return (preg_match("/^[0-9]+$/", $value));
   } else {
      return false;
   }
}


How can it be changed to accept negative numbers ass well?

3 replies

^-?[0-9]+(\.{0,1})[0-9]*$

Just add a -?
See above
Perhaps for the second preg match as well.
Thanks, It is working now
smile
Also in the second preg match?
author douwe_yntema
forumCode Snippet and functions - 8
replies4 posts
viewed766 times
activeLast updated on 1 year ago

Related

Isnum
Started by douwe_yntema douwe_yntema - 4 posts
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: Wanabo, douwe_yntema