Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Validate Date, US Phone# and Radio Button in jQuery PlugIn

Posted on 2010-09-24
13
Medium Priority
?
741 Views
Last Modified: 2012-05-10
Hi Experts,
I need the followings to validate using jQuery PlugIn.  Please try to help me.

1. Date in MM/DD/YYYY format.
2. Us Phone Number 999-999-9999 format.
3. Radio Button (if not selected)

Any kind of help is appreciated.  Thank you in advance.
0
Comment
Question by:RadhaKrishnaKiJaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
13 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33756625
1) check this
http://stackoverflow.com/questions/511439/custom-date-format-with-jquery-validation-plugin

the reg-ex format would be
\d{2}/\d{2}\\d{4}

2) similarly the reg-ex for US phone number will be
\d{3}\-\d{3}\-\d{4}
check this also
http://docs.jquery.com/Plugins/Validation/CustomMethods/phoneUS

3) http://stackoverflow.com/questions/277589/validation-of-radio-button-group-using-jquery-validation-plugin
this will be a straightforward one

you need to add
radioButtonId : true,

in the rules
0
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 33772639
Hi gurvinder372,
I tested all of the above.  
1.  The date validation did not work at all.  In fact the example code contains date validation for an Australian Date format.  Also, this is not an working code.  Do you have any other suggestion?
2.  The phone# working fine.  Thank You.
3.  The RadioButton selection works when Html tag is used.  It doesn't work when ASP tags are used such as see the codes below.  Please provide me any other solution if you have.  

Thank you gurvinder372 for your help.

                                          <tr>
                                                <td align="center" colSpan="2"><asp:panel id="Panel1" runat="server"><FONT class="label">
                                                                  <asp:RadioButton id="rbUnitedStates" runat="server" TextAlign="Left" Text="United States" checked
                                                                        GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                                                                  <asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                                                            </FONT>
                                                      </asp:panel></td>
                                          </tr>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33894257
Check this plugin : http://digitalbush.com/projects/masked-input-plugin/

>3.  The RadioButton selection works when Html tag is used.  It doesn't work when ASP tags are used such as see the codes below.  Please provide me any other solution if you have.

Put you radio button in a div with the id of the groupname (but you can put another id...) :

Here the div with id << Region >> :


<tr>
<td align="center" colspan="2">
    <asp:panel id="Panel1" runat="server">
            <div id="Region">
                <font class="label">
                <asp:RadioButton id="rbUnitedStates" runat="server" TextAlign="Left" Text="United States" GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                <asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                </font>
            </div>
    </asp:panel>
</td>
</tr>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33894269
and use :


<script language="javascript" type="text/javascript">
    function validateRBChecked(groupname) {
        var inputs = document.getElementById(groupname).getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "radio" && inputs[i].checked) return true;
        }
        alert("Choose a " + groupname);
        return false;
    }
</script>

Open in new window

0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 2000 total points
ID: 33894277
test page :


<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript">
    function validateRBChecked(groupname) {
        var inputs = document.getElementById(groupname).getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "radio" && inputs[i].checked) return true;
        }
        alert("Choose a " + groupname);
        return false;
    }
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table>
<tr>
<td align="center" colspan="2">
    <asp:panel id="Panel1" runat="server">
            <div id="Region">
                <font class="label">
                <asp:RadioButton id="rbUnitedStates" runat="server" TextAlign="Left" Text="United States" GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                <asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:RadioButton>&nbsp;&nbsp;
                </font>
            </div>
    </asp:panel>
</td>
</tr>
</table>
<asp:Button ID="mySubmit" runat="server" Text="Submit" OnClientClick="return validateRBChecked('Region')"  />
</asp:Content>

Open in new window

0
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 33926250
Hi leakim971, Thank you for your reply.  I tried your above code.  In my case it did not compile.  So, I modified the code little bit as below.  Still the Javascript code is not executed on Submit button click.  Please try to fix this code if possible.  Thank you very much for your help.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>demo16</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

            <script language="javascript" type="text/javascript">
                  function validateRBChecked(groupname) {
                        alert("Inside Javascript code...");
                        var inputs = document.getElementById(groupname).getElementsByTagName("input");
                        for (var i = 0; i < inputs.length; i++) {
                        if (inputs[i].type == "radio" && inputs[i].checked) return true;
                      }
                      alert("Choose a " + groupname);
                        return false;
                  }
            </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <td align="center" colspan="2">
                        <asp:panel id="Panel1" runat="server">
                              <DIV id="Region">
                                    <asp:RadioButton id="rbAmerica" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 48px" runat="server"
                                          GroupName="Region"></asp:RadioButton></DIV>
                        </asp:panel>
                  </td>
                  <asp:RadioButton id="rbCanada" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px" runat="server"
                        GroupName="Region"></asp:RadioButton>
                  <asp:Button ID="mySubmit" runat="server" Text="Submit" OnClientClick="return validateRBChecked('Region')"  />
            </form>
      </body>
</HTML>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33926280
Very strange your page run fine for me...

below the generated page, you may compare it with your...
I'm going to sleep, see you later.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<HTML> 
      <HEAD> 
            <title>demo16</title> 
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> 
            <meta name="CODE_LANGUAGE" Content="C#"> 
            <meta name="vs_defaultClientScript" content="JavaScript"> 
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> 
 
            <script language="javascript" type="text/javascript"> 
                function validateRBChecked(groupname) {
                    alert("Inside Javascript code...");
                    var inputs = document.getElementById(groupname).getElementsByTagName("input");
                    for (var i = 0; i < inputs.length; i++) {
                        if (inputs[i].type == "radio" && inputs[i].checked) return true;
                    }
                    alert("Choose a " + groupname);
                    return false;
                }
            </script> 
      </HEAD> 
      <body > 
            <form method="post" action="Default4.aspx" id="Form1"> 
<div class="aspNetHidden"> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE3NjU1MjYzMDBkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYEBQlyYkFtZXJpY2EFCXJiQW1lcmljYQUIcmJDYW5hZGEFCHJiQ2FuYWRhU8+xJZowthrzyJyx6jmGW783FORmeBKafphkuMnHrZc=" /> 
</div> 
 
<div class="aspNetHidden"> 
 
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAK5hq/kAwLH9YqIAwLfi+nVCAKRq/PlBzY+e88TgbZiEvdHZfvpl0bs2vpkXxaEt6xb6825VS82" /> 
</div> 
                  <td align="center" colspan="2"> 
                        <div id="Panel1"> 
	
                              <div id="Region"> 
                                    <span style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 48px"><input id="rbAmerica" type="radio" name="Region" value="rbAmerica" /></span></DIV> 
                        
</div> 
                  </td> 
                  <span style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px"><input id="rbCanada" type="radio" name="Region" value="rbCanada" /></span> 
                  <input type="submit" name="mySubmit" value="Submit" onclick="return validateRBChecked(&#39;Region&#39;);" id="mySubmit" /> 
            </form> 
      </body> 
</HTML>

Open in new window

Clipboard08.jpg
0
 

Assisted Solution

by:RadhaKrishnaKiJaya
RadhaKrishnaKiJaya earned 0 total points
ID: 33986683
Hi leakim971,
Thank you for your help.  The code did not execute on my machince for some reason.  Now, I changed the code to execute the on submit rather than on click.  It is working now.  But, it is all your code only.  The 100% credit goes to you.  See the working code below.  Probably you can take a look the code at your leisure time.  Thank you very much for your help.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
      <HEAD>
            <title>demo16</title>
            <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
            <meta name="CODE_LANGUAGE" Content="C#">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
            <script language="C#" runat="server">
   
            void Page_Load(object s, EventArgs e)
            {
            }

            private void btnClear_Click(object sender, System.EventArgs e)
            {
                }

            private void btnSend_Click(object sender, System.EventArgs e)
            {
                            string emailBody;
                           string toAddress;
                           string fromAddress;
                           string subject;

                           fromAddress = "new.user@bcdtravel.com";

                           subject = "New User Request from ";
                     toAddress = "online.travel@turner.com";
                     toAddress = "satyabrata.mahapatra@bcdtravel.com ";
                }
            </script>
            <script language="javascript" type="text/javascript">
                  function validateRBChecked(groupname) {
                        //alert("Inside Javascript code...");

                        var inputs = document.getElementById(groupname).getElementsByTagName("input");
                      //alert("inputs.length: " + inputs.length);

                        for (var i = 0; i < inputs.length; i++) {
                        if (inputs[i].type == "radio" && inputs[i].checked) return true;
                      }
                      alert("Choose a " + groupname);
                        return false;
                  }
            </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server" OnSubmit="return validateRBChecked('Region')">
                  <td align="center" colspan="2">
                        <asp:panel id="Panel1" runat="server">
                              <DIV id="Region">
                                    <asp:RadioButton id="rbAmerica" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 48px" runat="server"
                                          GroupName="Region"></asp:RadioButton>
                                    <asp:RadioButton id="rbCanada" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px" runat="server"
                                          GroupName="Region"></asp:RadioButton></DIV>
                        </asp:panel>
                  </td>
                  <asp:button id="btnSend" onclick="btnSend_Click" runat="server" Text="Submit" tabIndex="36"
                        style="Z-INDEX: 103; LEFT: 144px; POSITION: absolute; TOP: 88px"></asp:button>
            </form>
      </body>
</HTML>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33987543
The submit buttons :
<asp:Button ID="mySubmit" runat="server" Text="Submit" OnClientClick="return validateRBChecked('Region')"  />

versus

<asp:button id="btnSend" onclick="btnSend_Click" runat="server" Text="Submit" tabIndex="36"
                        style="Z-INDEX: 103; LEFT: 144px; POSITION: absolute; TOP: 88px"></asp:button>

Open in new window

0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 34026709
Thoug I am saveral questions in this case, and some are yet to be answered, I am going to close this case and open another for the rest of my questions to avoid confusion.  Thank you all for your wonderful support.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34026806
You're welcome! Thanks for the points!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question