473,394 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2070
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

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

Similar topics

19
by: aa | last post by:
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script...
7
by: Tom Szabo | last post by:
Hi, I am looking for some library that will allow developing web-based applications in PHP. I am looking for something that is as close as possible to a windows like application as possible. ...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
6
by: Jim | last post by:
How do I check if javascript is enabled in PHP? TIA, Jim
5
by: gabriele | last post by:
Hi, i'm new in this newsgroup, I'm working on a web based managerial software in my company and, for speed-up my work, have created a framework This framework uses the PHP and JAVASCRIPT...
2
by: R.F.J. de Laat | last post by:
Hi, I'm developing an application that runs on my intranet using PHP and JS. It's goal is quite simple, to convert an internet browser into a media- center. Allowing any device with a...
5
by: jkershner | last post by:
I have a js script inside php code that is connected to mysql, the php code is listing the results from the query then, the onmouseover function is supposed to show the description of the title for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.