please tell what validations i have to apply the given fields

Posted by Ramanagudlur under ASP.NET on 3/13/2012 | Points: 10 | Views : 1049 | Status : [Member] | Replies : 10
HEllo every body i want to put validations for the following fields could u plz help me thanks
the fields are

as following


User Type , Email , User Name , Mobile No. , Full Name , Company Name ,  Address , Profile, City , Country ,Looking For , Monthly Income , Occupation ,Land Phone , Language Spoken , Years of Operation , Area of Operation , Location .



Thanks

ramanagv


Responses

Posted by: Patel28rajendra on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi !

You should use foloowing Validation control

1. Required Field validator - for field which is mandatory
2. Regular Expression Validator- To check if the entered values is valid or not ex. Email, Mobile,phone number etc.


you can also use range validator and custom validator if needed

If you want to display error message in group then you can use Validation summary.



Thanks

Regards
Rajendra Patel

R D Patel

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/13/2012 [Member] Silver | Points: 25

Up
0
Down
You can use javascript and validation controls

Thanks,
Sanjay

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramanagudlur on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down


Thank u very much

ramanagv

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramanagudlur on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down
how to write java script to validations please help me with example


ramanagv

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi


you can write javascript for this as follow



<script language="javascript" type="text/javascript">
function validate()
{
if(document.getElementById("<%=txtname.ClientID %>").value=="")
{
alert("Please Enter Name");
document.getElementById("<%=txtname.ClientID %>").focus();
return false;
}
if(document.getElementById("<%=ddlgender.ClientID%>").value=="0")
{
alert("Please select Gender");
return false;
}
// Mobile validation
var y = document.form1.txtmobile.value;
if(isNaN(y)||y.indexOf(" ")!=-1)
{
alert("Invalid Mobile Number")
return false;
}
if (y.length>10||y.length<10)
{

alert("Invalid Mobile Number");
return false;
}


// email validation
if(document.getElementById("<%=txtemail.ClientID%>").value=="")
{
alert("Please Enter Email Id");

return false;
}
var email = document.getElementById('txtemail');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value))
{
alert('Please provide a valid email address');
return false;
}


}
</script>



and add textbox,dropdownlist and button to your html code

<asp:TextBox ID="txtname" runat="server"></asp:TextBox>

<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
<asp:TextBox ID="txtmobile" runat="server"></asp:TextBox>


<asp:DropDownList ID="ddlgender" runat="server" Width="90px">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">Male</asp:ListItem>
<asp:ListItem Value="2">Female</asp:ListItem>
</asp:DropDownList>


<asp:Button ID="btnsubmit" runat="server" OnClientClick="return validate();" Text="Submit" OnClick="btnsubmit_Click" />


here
document.getElementById("<%= ID of control.ClientID %>").value

this will get the value of the particular control
and you can check for different condition as per requirement

please Mark as Answer if it helps

Thanks

Rajendra Patel



R D Patel

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramanagudlur on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down

Thank u very much Mr Rajendrapatel Keepit up

ramanagv

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ramanagudlur on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down

hello goodmrng i have a dought i am very new to this javascript could u please tell me where can i write javascript i mean where can write i mean in source or click event where? please tell me please

Thanks&Regards
Ramana

ramanagv

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Write javascript on .aspx page.

you can write anywhere on .aspx page between <script></script> tag.

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/14/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
You can write javascript in .aspx file as suggested by Himanshu.

If you want to reuse a javascript function then its better to write it in filename.js file and reuse it from anywhere of your project.
For that you make a reference in your page header and then use the function.

You can also write javascript in codebehind, refer to following link:
http://www.dotnetspider.com/forum/17919-how-write-javascript-my-codebehind-page.aspx

Thanks,
Sanjay

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi


Normally you can write java script in head section with
<script language="javascript" type="text/javascript">
</script>

or you can make external file with .js extension and include its reference in head section


Please Mark as Answer If it helps

Thanks
Rajendra Patel

R D Patel

Ramanagudlur, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response