RadhaKrishnaKiJaya
asked on
Validate Date, US Phone# and Radio Button in jQuery PlugIn
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.
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.
ASKER
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:R adioButton > &nb sp;
<asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:R adioButton > &nb sp;
</FONT>
</asp:panel></td>
</tr>
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:R
<asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:R
</FONT>
</asp:panel></td>
</tr>
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 >> :
>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>
<asp:RadioButton id="rbCanada" runat="server" TextAlign="Left" Text="Canada" GroupName="Region"></asp:RadioButton>
</font>
</div>
</asp:panel>
</td>
</tr>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_defaultClientScri pt" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" type="text/javascript">
function validateRBChecked(groupnam e) {
alert("Inside Javascript code...");
var inputs = document.getElementById(gr oupname).g etElements ByTagName( "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:R adioButton ></DIV>
</asp:panel>
</td>
<asp:RadioButton id="rbCanada" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px" runat="server"
GroupName="Region"></asp:R adioButton >
<asp:Button ID="mySubmit" runat="server" Text="Submit" OnClientClick="return validateRBChecked('Region' )" />
</form>
</body>
</HTML>
<!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_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" type="text/javascript">
function validateRBChecked(groupnam
alert("Inside Javascript code...");
var inputs = document.getElementById(gr
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:R
</asp:panel>
</td>
<asp:RadioButton id="rbCanada" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 48px" runat="server"
GroupName="Region"></asp:R
<asp:Button ID="mySubmit" runat="server" Text="Submit" OnClientClick="return validateRBChecked('Region'
</form>
</body>
</HTML>
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.
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('Region');" id="mySubmit" />
</form>
</body>
</HTML>
Clipboard08.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
ASKER
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.
You're welcome! Thanks for the points!
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