473,785 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help : Validation for numeric type (PHP+JS)

9 New Member
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(WithoutConte nt(document.add .sprice.value))
{ errormessage += "\n\n\"PRIC E\" 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 2086
pbmods
5,821 Recognized Expert Expert
Moving to the JavaScript forum.
Jun 8 '07 #2
gits
5,390 Recognized Expert Moderator Expert
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 Top Contributor
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(WithoutConte nt(document.add .sprice.value))
{ errormessage += "\n\n\"PRIC E\" 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
2257
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 src="filename.js></script> This code initialises a Javascript variable var u="string";
7
2182
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. Say it would implement simple forms and browsers/grids. I have seen some of them like PRADO, but it is still too much web-like. Is there anything more windows like?
27
4623
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 = $doc->loadHTMLFile("./aBasicSearchResult.html"); if ( $res == true ) { $zip = $doc->getElementById('zipRaw_id')->value; if ( 0 != $zip ) {
27
4758
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
6
61605
by: Jim | last post by:
How do I check if javascript is enabled in PHP? TIA, Jim
5
1674
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 technology. the innovation in this work is the approach:
2
1300
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 network-connection and browser to access all my media which is stored at my server. The main reason for starting this project, is that my Nintendo Wii cannot function as a media-center due to it's small storage capacity. Another reason is that I don't want...
5
4626
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 that specific title, however, the mouseover is displaying all the descriptions for every title. Also, will you let me know if I have code in here that is not needed? I'm very new to php/js <script type="text/javascript" language="JavaScript">...
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.