通过Javascript文本框显示错误年龄小于18岁

通过Javascript文本框显示错误年龄小于18岁

本文介绍了通过Javascript文本框显示错误年龄小于18岁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function checkDate(sender,args)
{
//create a new date var and set it to the
//value of the senders selected date
var selectedDate = new Date();
selectedDate = sender._selectedDate;
//create a date var and set it's value to today
var todayDate = new Date();
var mssge = "";

if(  todayDate -selectedDate >=18)
{
/
alert("Warning! - Date of Birth  is  valid  ");
}
}
    Date Of  Birth
            <td style="width: 292px">
            
            <asp:TextBox id="TextBox3" runat="server"  ValidationGroup="a">
 <asp:calendarextender id="CalendarExtender2" targetcontrolid="TextBox3"  runat="server" OnClientDateSelectionChanged="checkDate">>


                <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" TargetControlID="RequiredFieldValidator3">
                
               
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ErrorMessage="RequiredFieldValidator"  Display="None" 
                    ControlToValidate="TextBox3" SetFocusOnError="True" ValidationGroup="a">
              <asp:Button ID="Button1" runat="server" Text="Insert"  ValidationGroup="a" onclick="Button1_Click" 
                    style="width: 48px"  />
                   <asp:Label ID="Label2" runat="server" ForeColor="#FF6600" 
                    Text="Data  Sucessfully Inserted ">
Now   is   coding  inside  button  
 protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string constr;
            constr = WebConfigurationManager.ConnectionStrings["JAPITConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(constr);

            con.Open();
            string str = "insert   into  Doe_detail values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "')";
            SqlCommand cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
            Label2.Visible = true;
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
         
        }
        catch (Exception es)
        {
        }
    }</td>

推荐答案


var d1=new Date(1984,3,4);
var d2=new Date(2012,3,5);
var msec=d2-d1;
var mpy=1000*60*60*24*365.26;
var noofyears=msec/mpy;
noofyears= Math.floor(noofyears);//it will gives you exact years..


希望对您有帮助.


hope helps you..


这篇关于通过Javascript文本框显示错误年龄小于18岁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:14