-
Prospect
cegonsoft indiranagar | learn javascript under .net training
use of javascript in .net
Example of The CustomValidator Control in .net
The CustomValidator control performs its validation based on custom validation code
that you provide.You can write the client-side validation code using JavaScript or
server-side validation code using your preferred .NET language.
In the following code example, a Web page contains a TextBox called txtPassword,
an associated CustomValidator called cusCheckPassword, and a RequiredFieldValidator
called reqPassword because the custom script will not execute if a password is not entered.
A valid password must be between 6 and 14 characters and must contain at least one
uppercase letter, one lowercase letter, and one numeric character. A ValidationSummary
has also been added to the bottom of the Web page to show the validation error.
JavaScript Client-Side Validation
<script language="javascript" type="text/javascript">
function ValidatePassword(source, arguements)
{
var data = arguements.Value.split('');
//start by setting false
arguements.IsValid=false;
//check length
if(data.length < 6 || data.length > 14) return;
//check for uppercase
var uc = false;
for(var c in data)
{
if(data[c] >= 'A' && data[c] <= 'Z')
{
uc=true; break;
}
}
if(!uc) return;
//check for lowercase
var lc = false;
for(var c in data)
{
if(data[c] >= 'a' && data[c] <= 'z')
{
lc=true; break;
}
}
if(!lc) return;
//check for numeric
var num = false;
for(var c in data)
{
if(data[c] >= '0' && data[c] <= '9')
{
num=true; break;
}
}
if(!num) return;
//must be valid
arguements.IsValid=true;
}
</script>
Visit: Cegonsoft
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules