.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Post New Web Links

decimal value validation and round off by javascript

Posted By: hiral.hapani     Posted Date: August 21, 2010    Points: 0   Category :ASP.Net
The article decimal value validation and round off by javascript was added by hiral.hapani on Wednesday, June 02, 2010.

Hi All, I have createdone javascript by which you canvalidate a decimal value of any textbox for which you want. By thisjavascriptwecan bind user to enter only digits in textbox. and when he will enter any decimal value javascript will do round off it

View Complete Post

More Related Resource Links

Asp.net Javascript Validation dd/mm/yyyy format


Hi experts,

 I am trying to validate two textbox (fromdate,todate)

should alert a message when Fromdate is more than Todate

I could find only mm/dd/yyyy format in most of google search.

please give me a script or assist how to do this.



Javascript FromDate to Date Validation Help!

Hi,I want to check fromdate and todate in dd/mm/yyyy.The code below mentioned works perfect for single textbox(fromdate) ,but when tried to do for todate(textbox) it doesnot work properly.From Date Should not be greater than ToDate.Please Help.Below is the code:<html><head><title>Date Example</title><script type="text/javascript">    function isValidDate(sText) {        var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;        return reDate.test(sText);    }    function validate() {        var oInput1 = document.getElementById("txt1");        if (isValidDate(oInput1.value)) {            alert("Valid");        } else {            alert("Invalid!");        }    }</script></head><body>    <P>Date: <input type="

Javascript numbers only, & format it to Decimal

Hello Experts, I need some help guys ;( I want some javascript code that make sure that end user must enter only numbers on textbox (currency,number), no characters, also typed number will be formated to be decimal number, I mean if user type (22222), javascript should format the number to be (22,222.0) javascript function should be called while end user typing on Textbox. so if he enter character, then the character should be removed automatically. I read many posts that talked about this, but most of them are using the onkeypress(event), so if the user paste the text that code will not work. Please help me guys, I need this urgent

javascript for field validation on a textbox...

I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

radiobutton validation using javascript

hi' i have two radiobuttons and a button.On button click i have to validate whether the radiobutton is selected or not. I tried the following,but it is not working.pls help.<asp:RadioButton  runat="server" ID="rbyes" Text="Yes"  visible="true" GroupName="a"  /> <asp:RadioButton  runat="server" ID="rbno" Text="No" visible="true" GroupName="a" /> <asp:Button  ID="btnOk" runat="server" Text="OK" OnClick="btnOk_Click"  OnClientClick="return selectRadioButton();"/>function selectRadioButton(){var y=document.getElementById("ctl00_ContentPlaceHolder1_rbyes");var n=document.getElementById("ctl00_ContentPlaceHolder1_rbno");if(y.checked==false && n.checked==false){alert(Please select Yes/No");return false;}return true;}

Validation is not working in Custom List Form using JavaScript ddwrt:GenFireServerEvent()

Hii am creating custom New form for a list using sharepoint designer. i have added the below button for sumbit<input name="Submit1" type="submit" value="Submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={http://myserver/Lists/VTest/AllItems.aspx}')}" />                <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;                                    </xsl:text><input name="Submit2" type="submit" value="Cancel" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={http://myserver/Lists/VTest/AllItems.aspx}')}" />the problem is the validation is not working properly. it submits the page without entering values for the required fields.particularly the validation is not working for DateFields.let me know what is the problem here. is it a Bug?muthu

Delaying clientside validation Javascript


For performance reasons, I usually put all my javascripts at the end of my html page.

However, Html.EnableClientValidation() always generates client side validation script after the form in the middle of the document

Is there anything I can do to change this?

What if the MVC team add a DEFER attribute to the generated javascript validation script

so the generated script should like

<script type="text/javascript" defer="defer">
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }

validation group creation using javascript


Hi I want to create a validation group using javascript.

How can I do that? 

beginner validation: jquery vs javascript vs codebehind




I've a webform that has around 10 textboxes that are filled with information from an event trigered by combobox.  so far so good.  The thing is that I need  that some textboxes should be validated against the sum of values of others,  and according to that assign given values.  Other textboxes should have a value according to those sum and datefield values.  I haven't found validation controls for asp.net so I assume that I should to it with javascript or jquery.  My concern as asp.net beginner is what happens if the user disables javascript?  If I make it with codebehind I'll have to refresh the page many times as I have many controls to validate.  What can I do ?


thanks in advance.



time in am/pm javascript validation.



I have a time range such as 12:00 am to 11.59 pm,

now in two text boxes i want that no body can go beyond this range how can i achieved it through java script

please help....

Javascript validation


how  to write validations for

Phone number

eg: (040)-(12345678)

and alphanumeric

like uppercase & lower case with '   

Javascript validation


Hi there I m confused about how to validate data at time editing data with gridview, I converted all fields of gridview into template so in code it can be seen textboxes as TextBox1,TextBox2.....now i attached  javascript function with update button. right now I am having error so please have a look at code and reply javascript code to access textbox in gridview in editmode

 function validateData(TextBox2) {
        var sta = false;
            var gridViewID = "<%=GridView_courses.ClientID %>";
        var gridView = document.getElementById(gridViewID);
        var gridViewControls = gridView.getElementsByTagName("TextBox");

        for ( i = 0; i <= gridViewControls.length - 1; i++)

           if (gridViewControls[i].type == "text") {
                if (gridViewControls[i].value == " " || gridViewControls[i].value == null) {

                    sta = true;
                    alert("Error in input");

                if (sta == true) {
                    alert('Quantity must be greater than 0');
                    return false;
                else {

                    return true;


Round off Decimal to 2 places in jQuery


Hi everyone,

How come the following code does not work:



var t_o_t_a_l = parseFloat(total.toString()).toFixed(2);



Round Gridview footer template textbox value based on this JavaScript



This is my aspx javascript to get total in gridview footer template.. its working fine

The problem is : some time it show footer value is 6.9999999999

I need 6.99 as a result how to achieve this.

Aspx page:-

<script type="text/JavaScript">
function updateControls(elementId)
 var parentElementRef = document.getElementById(elementId);
 var elementRefArray = parentElementRef.getElementsByTagName('INPUT');
 var textBoxTotals = 0;

 for (var i=0; i<elementRefArray.length; i++)
  var elementRef = elementRefArray[i];

  if ( (elementRef.type == 'text') && (elementRef.gridTextBoxType == 'calcTextBox') )
   var textBoxAmount = parseFloat(elementRef.value);
   if ( isNaN(textBoxAmount) == true )
    textBoxAmount = 0;

   textBoxTotals += textBoxAmount;

 if ( isNaN(textBoxTotals) == true ) 
  textBoxTotals = 0;

 for (var i=0; i<elementRefArray.length; i++)
  var elementRef = elementRefArray[i];

  if ( (elementRef.type == 'text') && (elementRef.gridTextBoxType == 'totalsTextBox') )
   elementRef.value = textBoxTotals;
// -->


protected void Gridview1_RowDataBound(object sender, Grid

ASP.Net and Javascript validation hack



Suppose i use Javascript validation in my web site, now i save that page and modify the validation code and then post the data, is it possible or not? If yes then how we prevent our website from this type of hacking?

Javascript Date Validation



I have a few Date validations to perform. I have the following columns "BirthDate","College Review Date", "Project Review Date" created in the custom list. In the Column Date and Time format option, I had choosen "Date Only" format.

I want to do some javascript validations on the date created. For example, BirthDate must be less than or equal to System Date. If the users selects a day greater the System Date, I want to alert the user. The alert should be provided after the date selection has changed, and not on the "OK" button click.

How to achieve this using javascript?

Thank you

javascript validation problem?


Hi i want to validate and display an error message using javascript when a user enters less than 12 characters and below is my code

<script language="javascript" type="text/javascript">
function validateElements()
var username=document.getElementById('TextBox2').value;
document.getElementById('Label1').innerText="Userid Less than 12 characters";
return false;

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return validate();" />

but when i press the button nothing is happened,help me with this??

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend