473,626 Members | 3,427 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Valider un formulaire pour un champs >0 et Integer

J'ai un formulaire avec un seul champ text appelé "unite" et un
bouton.

En javascript j'aimerai utiliser un script qui interdise les valeurs
de type "char" et soit supérieur à 0

J'ai trouvé ce code mais je ne sais pas comment l'appliquer,
fonctionne-t-il?

<script>
function controlerNombre (valeur, limites) {
// contrôle si la valeur d'un champ est un nombre conforme

valeur = valeur.replace( " ", "");
if (isNaN(valeur)) var ok = false;
else {
if (limites != "") {
if (typeof limites == "string")
eval("ok = (" + valeur + " " + limites + ");");
else if (limites.length == 2)
eval("ok = ((" + valeur + " " + limites[0] + ") && (" +
valeur + " " + limites[1] + "));");
}
else var ok = true;
} return ok;
}
</script>
J'ai essayé mais cela ne fonctionne pas??
Jul 23 '05 #1
3 3887
pascal Joseph wrote:
En javascript j'aimerai utiliser un script qui interdise les valeurs
de type "char" et soit supérieur à 0


<form action="foo" onsubmit="retur n validate(this)" >
<input type="text" name="unite">
<input type="submit">
</form>

<script type="text/javascript">
function validate(f, v){
return v=f.elements["unite"].value, /^\d+$/.test(v) && +v>0;
}
</script>
Quant au mois de mars...:-)
Jul 23 '05 #2
JRS: In article <6b************ **************@ posting.google. com>,
dated Thu, 24 Feb 2005 06:20:45, seen in news:comp.lang. javascript,
pascal Joseph <jo****@pcl.c h> posted :
En javascript j'aimerai utiliser un script qui interdise les valeurs
de type "char" et soit supérieur à 0

J'ai trouvé ce code mais je ne sais pas comment l'appliquer,
fonctionne-t-il?
...
J'ai essayé mais cela ne fonctionne pas??


C'est m*rde.

OK = /^[1-9]\d*$/.test(valeur)
ou comme OK = /^[1-9]\d{1,3)$/.test(valeur) // max 9999

Lisez <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>; et FAQ 4.16.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3
Merci pour ces réponses, je retiendrai pour l'instant ce script. Mais
si celui-ci me donne en plus des messages d'alertes, je n'ai pas pu le
faire partir vers la page action="ajouter _panier"?? si quelqu'un peu
m'aider!
Ce formulaire est compris dans une boucle qui affiche chaque fois
l'article et le bouton commander, ainsi que les champs cachés pour le
produit.

Le script est celui-ci:

<html><form action = "ajouter_panier ">
<input type=text name=unite>
<input type="button" value="valider"
onclick="
var valeur = document.forms[0].unite.value.re place(',','.');
if(!(valeur*1) || Math.round(vale ur/2)<=0)
alert('entrez un nombre superieur a zero');
else
alert('bonne valeur !');">
</form></html>
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2680
by: WebRod | last post by:
Bonjour, comment savoir en moins de 5 secondes (enfin rapidement quoi) combien de nouveaux messages non récupérés se trouvent dans une BAL sur une serveur POP3 (pas d'imap donc)???? (en sachant que lorsque l'on récupère les emails, on ne les supprime pas du serveur au fur et à mesure) Parceque OUTLOOK y arrive bien lui!!
2
3026
by: grigoo | last post by:
bonjour a tous je me presente a vous::: greg dit le grigoo sur le web ,,etudiant en bioinformatique a montreal et jusqu au cou dans notre language prefere....java. et biojava.. et je suis en un newbee dans ce domaine et me dit que l homme est bien peu de chose voici en definitive mon probleme>>> je construit une classe appele symbolListWithGap. dans celle j y mets un constructeur:::: symbolListWithGap qui recoit
0
1871
by: tao | last post by:
Salut à tous Je dois réaliser une application ou j'ai besoin de sauvegarder des données de manière régulière. Au début je pensais utiliser une base de donnée de type sql mais le pc ou tournera l'application n'est pas connecté à un réseau et est assez vieux. De plus, pour facilier les sauvegardes pour les utilisateurs, j'ai pensé qu'il serait peut etre préférable de sauvegarder les données sous forme de fichier xml par exemple....
0
438
by: jmjacquel | last post by:
Salon IRC pour la communauté des utilisateurs et développeurs dotNET Bonjour à tous, Un nouveau salon IRC pour la communauté des utilisateurs et développeurs dotNET a été créé et enregistré ce jour. Pour y accéder, utilisez un client IRC tel que mIRC ou autre, connectez vous au serveur irc.voila.fr, et rejoingnez le salon #dotNet.
2
1997
by: NDAKI MBOULET | last post by:
J'ai un problème pour écrire un programme. Voici mon sujet: Ecrire en c++ un programme qui reçoit en entrée une suite d'instruction encadrées par les mots clés BIBODLE et LISUK dans un langage quelconque appélé Bazoréen et rend en sortie soit une liste des erreurs rencontrées lors du traitement, soit un programme source en c++, sans erreurs de syntaxe ni de semantique, compilable et exécutable. Les éléments du bazoréen sont: 1 opérateurs
5
1763
by: Sébastien Ramage | last post by:
Bonjour à tous, Dans la folie j'ai installé le nouveau python, impatient de voir les nouveautés mais je pense que j'ai été un peu rapide car j'ai voulu utiliser pyOpenGL et là problème il n'existe pas pour python 2.5 ?!!! de plus il semble que pyopengl est été abandonné depuis 2005 ? plus rien ne bouge sur le site... je suis sous windows et je ne dispose pas des outils pour faire moi
11
2658
by: Steven Woody | last post by:
long i = nnn; long j; double d; d = i; j = ( long )d; in this case, i == j ? thanks.
4
2974
by: dragony2000 | last post by:
I want to solve these questions using C# , Please !!! ************************************************************* 1- The factorial method is used frequently in probability problems. The factorial of a positive integer n (written n! and pronounced “n factorial”) is equal to the product of the positive integers from 1 to n. Write a program that evaluates the factorials of the integers from 1 to 20 with different integer data types....
0
8272
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
8644
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...
0
8514
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7206
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
6126
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
4094
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
4208
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.