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



Home Answers Viewqa JSP-Servlet alert for validation

Have Programming Question? Ask it here!
 
 
 


megha singhal
alert for validation
1 Answer(s)      2 years and 3 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
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
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:<
change appearance of alert box
change appearance of alert box  how to change the appearance of an alert() box
javascript prompt alert
javascript prompt alert   Sending a prompt alert using a JavaScript function
Javascript alert message
Javascript alert message   How to send an alert message to a user in JavaScript
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
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 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
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
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
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
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
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
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
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
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
Alert Control in Flex4
Alert control in Flex4: The Alert control is a MX component. It has no Spark component. The Alert control contains a message, icon, title, and buttons. Flex uses the show() method of the Alert classfor open a dialog box. The Syntax
J2ME Alert Example
J2ME Alert Example      ... to create  alert through sound. In this example we are using AlertType class for the different alert. The AlertType() class has only one method: playSound
form validation
form validation  how the form validation is done in jsf form using javaScript
NSURL Validation
NSURL Validation  How to validate a NSURL string using special character validation
validation query
validation query  where I should kept properties file inside struts Web application
Validation - Struts
Validation  what is the best way to use validation in Struts?either "validation.xml" or JavaScript
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
email validation
email validation  during email validation.... after domain name which it means if example example@gmail.co .... this address allowed by any validation program .... but i want to show invalid email address because domain name com
Date Validation
Date Validation  Hi, I need Date Validation using java in spring framework. Please Anyone help me... Thanks in advance
comboBox validation
comboBox validation  dear sir. i want to know . how to validate radio button in struts using xml validation. thanks
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
String Validation
String Validation changing password  Hi. I have a HTML coding in that I have to check whether the value given in the 2 password fields are same...!=document.f.confirm.value){ alert("New Password and Confirm Password should be same! Re
simple javascript validation for numbers
simple javascript validation for numbers  simple javascript validation for register number   Here is a html code that accepts number from...; <title>Mobile number validation using regex</title> <script
javascript regex validation alphanumeric
javascript regex validation alphanumeric  How to write javascript regex validation for alphanumeric?   <html> <head> <title> alphanumeric validation using regex</title> <script type="text
javascript regex validation email
javascript regex validation email  How to write JavaScript regex validation for email?   <html> <head> <title>Email validation using regex</title> <script type="text/javascript">
date validation
date validation  sir, pls provide date validation code in javascript..we want to include it into our master form..   Please visit the following link: http://www.roseindia.net/mysql/datevalidation.shtml
validation - Framework
validation  how to validate the action forms in struts? could you please explain how cross validation is done for date?  You go the following url: http://www.roseindia.net/struts/struts-login-form.shtml
Struts validation
Struts validation  I want to put validation rules on my project.But after following all the rules I can't find the result. I have extended... validation rules,put the plugins inside strutsconfig.xml, put the html:errors tag
Advertisements
 

 

 

DMCA.com