473,383 Members | 1,792 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,383 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 2069
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.