<script type="text/javascript">
function isUrl(s) {
var regexp = /\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/
return regexp.test(s);
}
function trim(text) {
return text.replace(/^\s+|\s+$/g, "");
}
function checkUrls(sender, args) {
var urls = document.getElementById('<%=txtMisspellvalue.ClientID %>').value;
if (document.getElementById('<%=txtMisspellvalue.ClientID %>').value == null
|| document.getElementById('<%=txtMisspellvalue.ClientID %>').value == "") {
args.IsValid = false;
return;
}
else {
var textarea = document.getElementById('<%=txtMisspellvalue.ClientID %>');
var isOk = true;
var urlsArr = textarea.value.replace(/\r\n/g, "\n").split("\n");
for (i = 0; i < urlsArr.length; i++) {
if (urlsArr[i] != '') {
if (isUrl(trim(urlsArr[i]))) {
isOk = true;
}
else {
isOk = false;
}
}
}
if (isOk === true) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
}
</script>
<table>
<tr>
<td>
<asp:TextBox ID="txtvalue" runat="server" Width="195" Height="100" TextMode="MultiLine"></asp:TextBox>
<asp:CustomValidator ID="CSvtxtvalue" runat="server" ControlToValidate="txtvalue"
ClientValidationFunction="checkUrls" Display="None" ErrorMessage="" ValidateEmptyText="true"></asp:CustomValidator>
<cc1:ValidatorCalloutExtender ID="vce_txtvalue" runat="server" TargetControlID="CSvtxvalue">
</cc1:ValidatorCalloutExtender>
</td>
</tr>
</table>
No comments:
Post a Comment