gvalidate website address javascript by using Regular Expression in asp.net
Script block:
========
<script type="text/javascript">
function ValidateWebsiteAddress() {
var url = document.getElementById('<%=txtWebsiteAddress.ClientID %>').value;
var urlIsValid = ValidateWebAddress(url); alert("Website Address is valid?:" +urlIsValid );
return urlIsValid ;
}
function ValidateWebAddress(url) {
var webSiteUrlExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if (webSiteUrlExp.test(url)) {
return true;
}
else {
return false;
}
}
</script>
.aspx File
======
<asp:TextBox runat="server" ID="txtWebsiteAddress"></asp:TextBox>
<asp:Button runat="server" OnClientClick="return ValidateWebsiteAddress()" Text="Validate WebsiteAddress"/>
Script block:
========
<script type="text/javascript">
function ValidateWebsiteAddress() {
var url = document.getElementById('<%=txtWebsiteAddress.ClientID %>').value;
var urlIsValid = ValidateWebAddress(url); alert("Website Address is valid?:" +urlIsValid );
return urlIsValid ;
}
function ValidateWebAddress(url) {
var webSiteUrlExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if (webSiteUrlExp.test(url)) {
return true;
}
else {
return false;
}
}
</script>
.aspx File
======
<asp:TextBox runat="server" ID="txtWebsiteAddress"></asp:TextBox>
<asp:Button runat="server" OnClientClick="return ValidateWebsiteAddress()" Text="Validate WebsiteAddress"/>
Demo:
=====
No comments:
Post a Comment