Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet alert for validation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


megha singhal
alert for validation
1 Answer(s)      2 years and 7 months ago
Posted in : JSP-Servlet


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


Advertisement
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... the validation on the login form using Javascript method in JSP page.  Understand
validation
validation  validation
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
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.....  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
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
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
); 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
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
GETTING ALERT MESSAGE
GETTING ALERT MESSAGE  how to get an alert message when radio button is selected instead of checkbox
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
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, you can use this code for show the alert .. UIAlertView *alt = [[UIAlertView alloc] initWithTitle: @"Title" message: @"Any
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
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
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
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
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
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
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
validation files
validation files  If I place validation files in the folder where the action classes are present,will there any error arise
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
why alert box is not appearing in servlets...?
why alert box is not appearing in servlets...?  //example.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class adduser extends HttpServlet { public void init(ServletConfig config
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
 

 

 

DMCA.com