Hi,
this is my javascript validating the fields in mozilla FF but its working and validating only one field.
how to write the and how to works the script ............... ... -
function Test(){
-
-
-
alphaNumericInput(document.forms[0].dealerid);
-
-
digitsAlphabetsInput(document.forms[0].dealerid); //for digits only
-
alphabetsInput( document.forms[0].dealerid);//only alpha bets
-
-
}
-
-
function digitsInput(textField){
-
var regExp=/^[0-9]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return false;
-
-
alert("Only digits are allowed!");
-
textField.value = textField.value.replace(/[^0-9]/g,"");
-
}
-
function alphabetsInput(textField){
-
var regExp=/^[a-z A-Z]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return;
-
-
alert("Only alphabets symbols are allowed!");
-
textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
-
}
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
-
function digitsAlphabetsInput(textField){
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return;
-
-
alert("Only digits and alphabets are allowed!");
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
}
-
-
-
Thanks
ss.
16 1967 pbmods 5,821
Recognized Expert Expert
Heya, SS.
In test(), you're passing the same form element each time. Is this intentional?
-
function Test(){
-
-
-
alphaNumericInput(document.forms[0].dealerid);
-
-
alphabetsInput(document.forms[0].name);
-
alphabetsInput( document.forms[0].lname);
-
-
}
-
-
function digitsInput(textField){
-
var regExp=/^[0-9]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return false;
-
-
alert("Only digits are allowed!");
-
textField.value = textField.value.replace(/[^0-9]/g,"");
-
}
-
function alphabetsInput(textField){
-
var regExp=/^[a-z A-Z]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return;
-
-
alert("Only alphabets symbols are allowed!");
-
textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
-
}
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
-
function digitsAlphabetsInput(textField){
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
if(textField.value=="" || regExp.test(textField.value))
-
return;
-
-
alert("Only digits and alphabets are allowed!");
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
}
-
-
i am passing differet values through the Body Onload. but it is checking only one first one. The above given is some of my sample code.
pbmods 5,821
Recognized Expert Expert
Heya, SS.
You did not declare a function named alphaNumericInp ut(). Did you mean digitsAlphabets Input()?
gits 5,390
Recognized Expert Moderator Expert
hi ...
please have a close look at your script and the comments that i made within: -
function Test(){
-
// like pbmods said ... the following function is not declared
-
// and in your initial post all fields where 'dealerid' ...
-
alphaNumericInput(document.forms[0].dealerid);
-
-
alphabetsInput(document.forms[0].name);
-
alphabetsInput(document.forms[0].lname);
-
}
-
-
function digitsInput(textField){
-
var regExp=/^[0-9]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return false;
-
-
alert("Only digits are allowed!");
-
-
textField.value = textField.value.replace(/[^0-9]/g,"");
-
}
-
-
function alphabetsInput(textField){
-
var regExp=/^[a-z A-Z]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return;
-
-
alert("Only alphabets symbols are allowed!");
-
-
textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
-
}
-
-
// the following two lines are useless i think ... they are executed
-
// during load and assign an regEx that is never used and
-
// should give an error since textField is undefined here
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
-
function digitsAlphabetsInput(textField){
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return;
-
-
alert("Only digits and alphabets are allowed!");
-
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
}
-
fixing the function-name in the test-function should do the job. and a strict way to write down the code with strict indentation will help you a lot when searching matching brackets or useless lines of code ... delete them since they produce an error in our actual case ...
kind regards
hi ...
please have a close look at your script and the comments that i made within: -
function Test(){
-
alphaNumericInput(document.forms[0].dealerid);
-
-
alphabetsInput(document.forms[0].name);
-
alphabetsInput(document.forms[0].lname);
-
}
-
-
function digitsInput(textField){
-
var regExp=/^[0-9]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return false;
-
-
alert("Only digits are allowed!");
-
-
textField.value = textField.value.replace(/[^0-9]/g,"");
-
}
-
-
function alphabetsInput(textField){
-
var regExp=/^[a-z A-Z]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return;
-
-
alert("Only alphabets symbols are allowed!");
-
-
textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
-
}
-
-
function digitsAlphabetsInput(textField){
-
var regExp=/^[0-9\a-z A-Z]*$/;
-
-
if(textField.value=="" || regExp.test(textField.value)) return;
-
-
alert("Only digits and alphabets are allowed!");
-
-
textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
-
}
-
i removied that two lins also iam still geting same proble .now its not validating any field.
ss
gits 5,390
Recognized Expert Moderator Expert
;) you missed the first comment, and pbmods mentioned it too: - function Test(){
-
// there is no function called alphaNumericInput declared in your script
-
// you will get an error that alphaNumericInput is not a function
-
alphaNumericInput(document.forms[0].dealerid);
-
alphabetsInput(document.forms[0].name);
-
alphabetsInput(document.forms[0].lname);
-
}
declare that function or use the correct name of the function you want to use ...
kind regards
- function Test(){
-
digitsInput(document.forms[0].dealerid);
-
alphabetsInput(document.forms[0].name);
-
alphabetsInput(document.forms[0].lname);
-
}
iam using like this also not working do u know any validation script urls plz send that urls . ok
TQ
kind regards
gits 5,390
Recognized Expert Moderator Expert
... that's really confusing now, the following example works and uses all the code you provided ...
[HTML]<html>
<head>
<script>
function Test(){
digitsInput(doc ument.forms[0].dealerid);
alphabetsInput( document.forms[0].name);
alphabetsInput( document.forms[0].lname);
}
function digitsInput(tex tField){
var regExp=/^[0-9]*$/;
if(textField.va lue=="" || regExp.test(tex tField.value))r eturn false;
alert("Only digits are allowed!");
textField.value = textField.value .replace(/[^0-9]/g,"");
}
function alphabetsInput( textField){
var regExp=/^[a-z A-Z]*$/;
if(textField.va lue=="" || regExp.test(tex tField.value)) return;
alert("Only alphabets symbols are allowed!");
textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
}
function digitsAlphabets Input(textField ){
var regExp=/^[0-9\a-z A-Z]*$/;
if(textField.va lue=="" || regExp.test(tex tField.value)) return;
alert("Only digits and alphabets are allowed!");
textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
}
</script>
</head>
<body>
<form name="my_form">
<input type="text" name="dealerid"/>
<input type="text" name="name"/>
<input type="text" name="lname"/>
<input type="button" value="Validate " onclick="Test() ;"/>
</form>
</body>
</html>
[/HTML]
have a look at the firefox-javascript-console ... there has to be another error besides the one we found already ... how do you call Test();?
kind regards
gits 5,390
Recognized Expert Moderator Expert
... or another guess ... how should it work? may be it works for us but you want it to work another way? ...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kevin Lyons |
last post by:
Hello,
I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html
I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevinlyons/selectResults.html
I am passing countries, products, and courses. The first two display
|
by: lawrence |
last post by:
This PHP function prints out a bunch of Javascript (as you can see).
This is all part of the open source weblog software of PDS
(www.publicdomainsoftware.org). We had this javascript stuff working,
but it only worked for IE. You can see a working version here:
http://www.publicpen.com/designer/mcControlPanel.php
username: designer
password: designer123
However, I've tried to rewrite this so it would work in all browsers,
|
by: VictorG |
last post by:
Hello,
I am new to JS and am trying to add some HTML into a JS function. So
that when called the script as well as the HTML will be invoked. Is
there some type of embed mechanism, sort of the reverse of embedding JS
in an html page with the script tag. (which is what I am doing in this
case)
Is this even possible?
|
by: chrisdude911 |
last post by:
how do i add video into a javascript web page with my own custom
buttons?
|
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...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |