alert for validation

alert for validation

i want to put alert on the text box that enter data should be in DD/MM/YYYY format only through javascript validation.

View Answers

May 7, 2012 at 12:40 PM

  <html>  

  <script type='text/javascript'>   
        var dminyear = 1900;  
        var dmaxyear = 2200;  
        var sep= "/"  
        function checkNumber(str1){  
        var x;  
        for (x = 0; x < str1.length; x++){   
        var cr = str1.charAt(x);  
        if (((cr < "0") || (cr > "9")))   
        return false;  
        }  
        return true;  
        }  
        function getcharacters(s, sep){  
        var x;  
        var Stringreturn = "";  
        for (x = 0; x < s.length; x++){   
        var cr = s.charAt(x);  
        if (sep.indexOf(cr) == -1)   
        Stringreturn += cr;  
        }  
        return Stringreturn;  
        }  
        function checkFebruary(cyear)  
        {  
        return (((cyear % 4 == 0) && ( (!(cyear % 100 == 0)) || (cyear % 400 == 0))) ? 29 : 28 );  
        }  
        function finaldays(nr) {  
        for (var x = 1; x <= nr; x++) {  
        this[x] = 31  
        if (x==4 || x==6 || x==9 || x==11)  
        {  
        this[x] = 30}  
        if (x==2)  
        {  
        this[x] = 29}  
        }   
        return this  
        }   
        function dateValid(strdate)  
        {  
        var monthdays = finaldays(12)  
        var cpos1=strdate.indexOf(sep)  
        var cpos2=strdate.indexOf(sep,cpos1+1)  
        var daystr=strdate.substring(0,cpos1)  
        var monthstr=strdate.substring(cpos1+1,cpos2)  
        var yearstr=strdate.substring(cpos2+1)  
        strYr=yearstr  
        if (strdate.charAt(0)=="0" && strdate.length>1) strdatestrdate=strdate.substring(1)  
        if (monthstr.charAt(0)=="0" && monthstr.length>1) monthstrmonthstr=monthstr.substring(1)  
        for (var i = 1; i <= 3; i++) {  
        if (strYr.charAt(0)=="0" && strYr.length>1) strYrstrYr=strYr.substring(1)  
        }  

        pmonth=parseInt(monthstr)  
        pday=parseInt(daystr)  
        pyear=parseInt(strYr)  
        if (cpos1==-1 || cpos2==-1){  
        alert("The date format must be : dd/mm/yyyy")  
        return false  
        }  
        if (monthstr.length<1 || pmonth<1 || pmonth>12){  
        alert("Enter a valid month")  
        return false  
        }  
        if (daystr.length<1 || pday<1 || pday>31 || (pmonth==2 && pday>checkFebruary(pyear))         || pday > monthdays[pmonth]){  
        alert("Enter a valid day")  
        return false  
        }  
        if (yearstr.length != 4 || pyear==0 || pyear<dminyear || pyear>dmaxyear){  
        alert("Enter a valid 4 digit year between "+dminyear+" and "+dmaxyear)  
        return false  
        }  
        if (strdate.indexOf(sep,cpos2+1)!=-1 || checkNumber(getcharacters(strdate, sep))==false){  
        alert("Enter a valid date")  
        return false  
        }  
        return true  
        }  
        function validate(inputtxt)
        {  
        var crdt=inputtxt.value  
        if (dateValid(crdt)==false)  
        {  
        document.form1.text1.focus()  
        return false;  
        }  
        return true;
        }  
        </script>  

        <body onload='document.form1.text1.focus()'>  
        <form name="form1" action="#">  
        Enter a valid date [dd/mm/yyyy format] : <input type='text' name='text1'/>
        <input type="submit" name="submit" value="Submit" onclick="validate(document.form1.text1)"/>
        </form>  
        </body>  
        </html>









Related Tutorials/Questions & Answers:
alert for validation
alert for validation  i want to put alert on the text box that enter data should be in DD/MM/YYYY format only through javascript validation.  ...) if (cpos1==-1 || cpos2==-1){ alert("The date format must be : dd/mm/yyyy
alert
alert  after pressing ok button in alert message it has to stop...; if(username==""){ alert("Enter Username!"); return false; } if(password==""){ alert("Enter Password!"); return false; } return true; } </script> <
Advertisements
JSP Alert
JSP Alert          JSP Alert is used to put the validation on login... to create alert box in a JSP page. Before applying validation we create a JSP file
validation
validation  validation
alert in jsp
alert in jsp  if(pass.equals(pwd)) { Statement st1..."); %> alert("password is successfully changed"); <... Password"); %> <script> alert("please enter old Password
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
Alert in Servlet
Alert in Servlet  <p>Hi</p> <p>I want to delete record from oracle db, i need alert message saying 'Are you sure you want... of each row, when i click delete it shd alert me....This is my servlet code:<
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation
validation
validation  please help me to check validation for <form> <table class="form"> <tr> <td class="col1"> <label>Sno:</label> </td> <td
change appearance of alert box
change appearance of alert box  how to change the appearance of an alert() box
GETTING ALERT MESSAGE
GETTING ALERT MESSAGE  how to get an alert message when radio button is selected instead of checkbox
Javascript alert message
Javascript alert message   How to send an alert message to a user in JavaScript
javascript prompt alert
javascript prompt alert   Sending a prompt alert using a JavaScript function
Validation of datepicker
Validation of datepicker  I have a datepicker in my JSp...the seleted dates are put in a text box. I want the alert the user from selecting future... a future date is entered..How to do this validation in javascript or jsp
ModuleNotFoundError: No module named 'alert'
ModuleNotFoundError: No module named 'alert'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'alert' How to remove the ModuleNotFoundError: No module named 'alert'
GETTING AN ALERT MESSAGE
GETTING AN ALERT MESSAGE  how to get an alert message, if i select radio button instead of checkbox(associated with 3 dropdown list
JavaScript Alert YES NO
JavaScript Alert YES NO  How to send an alert to a user to confirm if there request is valid or not? I wants to send the alert message in Java Script... type="text/javascript"> function show_alert(my_string) { alert(my_string
Validation - Struts
Validation  How can i use validation framework i don't understand am...; Hi friend, Phone validation using javaScript function...==""){ alert ("This field is required. Please enter phone number without dashes
javascript statement alert
javascript statement alert  JavaScript Alert If Statement   JavaScript Alert if Statement <script type="text/javascript"> <...;/script> JavaScript Alert else if Statement <script type="text/javascript
alert box in iphone
alert box in iphone  hello, how can i show alert box in my iphone application??   hello,ADS_TO_REPLACE_1 you can use this code for show the alert .. UIAlertView *alt = [[UIAlertView alloc] initWithTitle: @"Title
JavaScript display variable in alert
in alert box? I am using javascript.   <html> <head> <script..."; var city = "Delhi"; alert(name +" is in "+ city); } </script> </head> <body> <input type="button" value="Click for Alert" onClick
Getting content of alert message into textfield
Getting content of alert message into textfield  how to get content of alert message into textfield using javascript   Getting content of alert message into text field 1)If you want the code in java, then here
Getting content of alert message into textfield
Getting content of alert message into textfield  how to get content of alert message into textfield using javascript   Getting content of alert message into text field 1)If you want the code in java, then here
jQuery alert()
jQuery alert() In this jQuery tutorial we will discuss how an alert box works in jQuery. Moreover, this tutorial will discuss in details about alert box in jQuery. In the given application here, alert boxes have been used to provide
Information Save Alert
Information Save Alert  Hi, Sir I am creating a web page there user can edit their information. I want a javascript that can show an alert message when user edit the information and trying to close or go to another page without
ModuleNotFoundError: No module named 'aws-alert'
ModuleNotFoundError: No module named 'aws-alert'  Hi, My Python... 'aws-alert' How to remove the ModuleNotFoundError: No module named 'aws-alert' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'django-alert'
ModuleNotFoundError: No module named 'django-alert'  Hi, My Python... 'django-alert' How to remove the ModuleNotFoundError: No module named 'django-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-alert'
ModuleNotFoundError: No module named 'django-alert'  Hi, My Python... 'django-alert' How to remove the ModuleNotFoundError: No module named 'django-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-alert'
ModuleNotFoundError: No module named 'django-alert'  Hi, My Python... 'django-alert' How to remove the ModuleNotFoundError: No module named 'django-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-alert'
ModuleNotFoundError: No module named 'django-alert'  Hi, My Python... 'django-alert' How to remove the ModuleNotFoundError: No module named 'django-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'kotti-alert'
ModuleNotFoundError: No module named 'kotti-alert'  Hi, My Python... 'kotti-alert' How to remove the ModuleNotFoundError: No module named 'kotti-alert' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'mail-alert'
ModuleNotFoundError: No module named 'mail-alert'  Hi, My Python... 'mail-alert' How to remove the ModuleNotFoundError: No module named 'mail-alert' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'nose-alert'
ModuleNotFoundError: No module named 'nose-alert'  Hi, My Python... 'nose-alert' How to remove the ModuleNotFoundError: No module named 'nose-alert' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'omsa-alert'
ModuleNotFoundError: No module named 'omsa-alert'  Hi, My Python... 'omsa-alert' How to remove the ModuleNotFoundError: No module named 'omsa-alert' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'rabbitmq-alert'
ModuleNotFoundError: No module named 'rabbitmq-alert'  Hi, My... named 'rabbitmq-alert' How to remove the ModuleNotFoundError: No module named 'rabbitmq-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'slack-alert'
ModuleNotFoundError: No module named 'slack-alert'  Hi, My Python... 'slack-alert' How to remove the ModuleNotFoundError: No module named 'slack-alert' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'supervisor-alert'
ModuleNotFoundError: No module named 'supervisor-alert'  Hi, My... named 'supervisor-alert' How to remove the ModuleNotFoundError: No module named 'supervisor-alert' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'timed-alert'
ModuleNotFoundError: No module named 'timed-alert'  Hi, My Python... 'timed-alert' How to remove the ModuleNotFoundError: No module named 'timed-alert' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'alert-grid'
ModuleNotFoundError: No module named 'alert-grid'  Hi, My Python... 'alert-grid' How to remove the ModuleNotFoundError: No module named 'alert-grid' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'aws-alert'
ModuleNotFoundError: No module named 'aws-alert'  Hi, My Python... 'aws-alert' How to remove the ModuleNotFoundError: No module named 'aws-alert' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'django-alert'
ModuleNotFoundError: No module named 'django-alert'  Hi, My Python... 'django-alert' How to remove the ModuleNotFoundError: No module named 'django-alert' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'easy-alert'
ModuleNotFoundError: No module named 'easy-alert'  Hi, My Python... 'easy-alert' How to remove the ModuleNotFoundError: No module named 'easy-alert' error? Thanks   Hi, In your python environment you
Version of com.michaelpardo>materialdesignicons-alert dependency
List of Version of com.michaelpardo>materialdesignicons-alert dependency
java hello and timer alert application
java hello and timer alert application  Hi, Please help me create a simple Java application that can display "Hello world" and current Time alert on mobile device screen using mobile screen emulator. Regards
javascript validation
validation and for email field it will check formate useing regularexpressions...;html    Email Validation function checkEmail...; if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter
jQuery Hello World alert
jQuery Hello World alert example    ... display "Hello World" alert box using jQuery. This application will use the JavaScript alert() method to display the "Hello World" message
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
jQuery alert()
jQuery alert() In this section we will discuss about alert box in jQuery. In an application alert boxes are used to provide information at run time... information at runtime. Alert box can be popped up after happening an event

Ads