Guest User

Untitled

a guest
Jul 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. 7
  2. 0
  3. 32
  4. 47534
  5.  
  6. asdf
  7. 35/gdf
  8. ../34.
  9.  
  10. etc..
  11.  
  12. if (preg_match("/^[0-9]$/", $original_stock))
  13. {
  14. $error .="Original stock must be numerical.";
  15. }
  16.  
  17. /^d+$/
  18.  
  19. /^d+.?d*$/
  20.  
  21. #Assuming $original_stock is a single value...
  22. if (is_int($original_stock)) {
  23. #Valid, do stuff
  24. }
  25. else {
  26. #Invalid, do stuff
  27. }
  28.  
  29. #Assuming $original_stock is an array...
  30. $valid = true;
  31. foreach ($original_stock as $s) {
  32. if (!is_int($s)) {
  33. $valid = false;
  34. break;
  35. }
  36. }
  37. if ($valid) {...}
  38. else {...}
  39.  
  40. /^[0-9]+$/
  41.  
  42. /^d+$/
  43.  
  44. /^d+(.d{1,2})?/
  45.  
  46. if (!preg_match("/^+$/", $original_stock)) {
  47. // error
  48. }
  49.  
  50. is_int
  51.  
  52. /^[0-9]$/
  53.  
  54. function validate_int($subject)
  55. {
  56. //Pattern is numbers
  57. //if it matches anything but numbers, we want a fail
  58. $pattern = '/[^0-9]/';
  59. $matches = preg_match($pattern, $subject);
  60. if($matches > 0)
  61. return false;
  62. else
  63. return true;
  64. }
  65.  
  66. if (ctype_digit($x) && $x > 0) {
  67. // here you go
  68. }
Add Comment
Please, Sign In to add comment