469,578 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Help : Validation for numeric type (PHP+JS)

Hi..
i have field in record using type : numeric,

how to make validation and i want viewing messagebox if user inputing character or empty?

this code just work for empty field, not for numeric type,
if(WithoutContent(document.add.sprice.value))
{ errormessage += "\n\n\"PRICE\" still Empty."; }
----------

this my full code:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="JavaScript">
  2. <!-- 
  3. function CheckValidation() {
  4. var errormessage = new String();
  5.  
  6. if(WithoutContent(document.add.sprice.value))
  7.     { errormessage += "\n\n\"PRICE\" still Empty."; }
  8. if(WithoutContent(document.add.spropadd.value))
  9.     { errormessage += "\n\nPROPERTY ADD still Empty."; }
  10. if(WithoutSelectionValue(document.add.sbed))
  11.     { errormessage += "\n\nBED list still Empty."; }
  12.  
  13. if(errormessage.length > 2) {
  14.     alert('NOTE:' + errormessage);
  15.     return false;
  16.     }
  17. return true;
  18.  
  19. function WithoutContent(ss) {
  20. if(ss.length > 0) { return false; }
  21. return true;
  22. }
  23.  
  24. function WithoutSelectionValue(ss) {
  25. for(var i = 0; i < ss.length; i++) {
  26.     if(ss[i].selected) {
  27.         if(ss[i].value.length) { return false; }
  28.         }
  29.     }
  30. return true;
  31. }
  32. //-->    
  33. </script>
  34. .
  35. .
  36. .
  37. <form name="add" onsubmit="return CheckValidation()" action="inputing.php" method="POST" enctype="multipart/form-data">
  38.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

thanks b4..
Jun 8 '07 #1
3 1927
pbmods
5,821 Expert 4TB
Moving to the JavaScript forum.
Jun 8 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

to test for a numeric value you may use javascripts isNaN() (isNotaNumber) method:

Expand|Select|Wrap|Line Numbers
  1. var foo = '12345.56';
  2. var bar = '12345gh';
  3.  
  4. // test will be false
  5. var test = isNaN(foo);
  6.  
  7. // test1 will be true
  8. var test1 = isNaN(bar);
  9.  
kind regards ...
Jun 9 '07 #3
dmjpro
2,476 2GB
Hi..
i have field in record using type : numeric,

how to make validation and i want viewing messagebox if user inputing character or empty?

this code just work for empty field, not for numeric type,
if(WithoutContent(document.add.sprice.value))
{ errormessage += "\n\n\"PRICE\" still Empty."; }
----------

this my full code:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="JavaScript">
  2. <!-- 
  3. function CheckValidation() {
  4. var errormessage = new String();
  5.  
  6. if(WithoutContent(document.add.sprice.value))
  7.     { errormessage += "\n\n\"PRICE\" still Empty."; }
  8. if(WithoutContent(document.add.spropadd.value))
  9.     { errormessage += "\n\nPROPERTY ADD still Empty."; }
  10. if(WithoutSelectionValue(document.add.sbed))
  11.     { errormessage += "\n\nBED list still Empty."; }
  12.  
  13. if(errormessage.length > 2) {
  14.     alert('NOTE:' + errormessage);
  15.     return false;
  16.     }
  17. return true;
  18.  
  19. function WithoutContent(ss) {
  20. if(ss.length > 0) { return false; }
  21. return true;
  22. }
  23.  
  24. function WithoutSelectionValue(ss) {
  25. for(var i = 0; i < ss.length; i++) {
  26.     if(ss[i].selected) {
  27.         if(ss[i].value.length) { return false; }
  28.         }
  29.     }
  30. return true;
  31. }
  32. //-->    
  33. </script>
  34. .
  35. .
  36. .
  37. <form name="add" onsubmit="return CheckValidation()" action="inputing.php" method="POST" enctype="multipart/form-data">
  38.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

thanks b4..

U also can do this by stop processing the non-numeric character.

Expand|Select|Wrap|Line Numbers
  1. function validateNumeric()
  2. {
  3.  if(event.keyCode >=48 && event.keyCode <= 57);
  4.  else event.keyCode = 0; //Stop processing the non-numeric character.
  5. }
  6. //Mind it event.keyCode ..... this is IE specific and i hope u know for others.
  7.  
Try it.
Best of luck.

Kind regards,
Dmjpro.
Jun 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

27 posts views Thread by one man army | last post: by
27 posts views Thread by Chris | last post: by
5 posts views Thread by gabriele | last post: by
2 posts views Thread by R.F.J. de Laat | last post: by
5 posts views Thread by jkershner | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.