Quantcast
Channel: Adobe Community : Popular Discussions - ColdFusion
Viewing all articles
Browse latest Browse all 14291

validation on numeric field

$
0
0

Hi. Does anyone know how to use javascript? I have a numeric field in my SQL table called Eng_Hrs. All I want to do is to make sure a number goes into this field instead of some text. It can have up to 2 decimal points. I've tried adding validate="float"  and adding validate="numeric", but that doesn't seem to work. I would rather do javascript anyway if I could since it would pop up a window that tells the user to enter a valid number into this field, and the form would not submit until this was entered correctly. I do have some javascript I used on a currency field somewhere else, but this field is just a number and can have 2 decimal points. I'm just not sure what I'm missing and why it's not working. Here's the javascript I have:


 

<SCRIPT LANGUAGE="JavaScript">

<!-- Original:  Wayne Nolting (w.nolting@home.com) -->

<!-- This script and many more are available free online at -->

 

 

<!-- Begin

function verify()

{

var PartNum=document.AddECNumber.Part_Number.value;

var regularExpression = new RegExp(/^[cC][0-9]/); //regular expression to check for a letter C followed by a number

 

 

if(regularExpression.test(PartNum)&& document.AddECNumber.CN_Entry_Initials.value == "N" && document.AddECNumber.Validation_Qty.value == "") { //this will return true if the input passes the regular expression

alert("Enter a Validation Quantity for this new Custom");

}

 

 

else if(document.AddECNumber.CN_Entry_Initials.value == "N" && document.AddECNumber.P_Drive_Docs_Initials.value == "i") { //this will return true if the input passes the regular expression

alert("You cannot select 'i' for docs to be removed for a new part");

}

 

 

else if(document.AddECNumber.CN_Entry_Initials.value == ""  && document.AddECNumber.SW_Model_Only.value == "0") { //this will return true if the input passes the regular expression

alert("ECO type required - Select (N)ew or (C)hange for eco line item");

}

 

 

else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C" && (document.AddECNumber.Release_Status_Initials.value == "U"

|| document.AddECNumber.Release_Status_Initials.value == "N")) { //this will return true if the input passes the regular expression

alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

}

 

 

else if(document.AddECNumber.PNR_BOM_Change_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value == "C" && document.AddECNumber.Release_Status_Initials.value == "U") { //this will return true if the input passes the regular expression

alert("ECO type required - Select (C)hange for eco line item and Select N for Release Status if PNR/BOM Change Only is yes");

}

 

 

 

 

else if(document.AddECNumber.Doc_Changes_Only.value == "1" && document.AddECNumber.CN_Entry_Initials.value != "C") { //this will return true if the input passes the regular expression

alert("ECO type required - Select (C)hange for eco line item since Doc Changes Only is yes");

}

 

 

else if(document.AddECNumber.Release_Status_Initials.value == "U"  && document.AddECNumber.SW_Model_Only.value == "1") { //this will return true if the input passes the regular expression

alert("For SW Model only change- Select 'N' for Release Status");

}

 

 

<!--- else if (document.AddECNumber.P_Drive_Docs_Initials.value == "i")

// self.location='eco_search.cfm'; --->

 

 

  // javascript below is to make sure the correct number value is entered into the Eng_Hrs field. It does not allow letters or more than 2 decimal places. It can also only do 999,999.99, not 1 million.

var validateForm = function () {

                var test = document.getElementsByName("Eng_Hrs");

                var success = true;

                for(var t = 0; t< test.length; t++){

                                var regex  = /^[1-9]\d*(((,\d{3}){1})?(\.\d{0,2})?)$/;

 

 

                                if (!regex.test(test[t].value.replace("$", ""))){

                                alert("You must enter a valid number in the Engineering Hours field");

                                success = false;

                                break;

                                }

                }

 

 

                return success;

}

 

 

 

 

else

{

document.AddECNumber.action ="add_new_ec_number_action.cfm";

document.AddECNumber.submit();

}

 

}

//  End -->

</script>

 

 

If you look at the line that starts with var validateForm = function () {    this is the code I'm trying to use. There's other things going on in this javascript, but I thought I would put the whole javascript in here so you could see it all. The cfform name is AddECNumber. The submit button looks like this:

<cfinput type="button" name="submitBtn" onclick="verify()" value="Add & Finish">

I don't need the dollar sign in this anymore. I'm just not sure how to do javascript. Can anyone tell me what I'm doing wrong? Thanks.

 

Andy


Viewing all articles
Browse latest Browse all 14291

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>