<asp:TextBox ID="txt_userid" runat="server" />
<asp:CustomValidator ID="CustomValidator" runat="server" EnableClientScript="true"
ErrorMessage="Userid should start with letter u followed with 7 digits"
ClientValidationFunction="validateuserid"
ControlToValidate="txt_userid" Display="Dynamic" >
</asp:CustomValidator>
<script type="text/javascript">
function validateuserid(sender, args) {
var Userid = document.getElementById('txt_userid').value;
if (Userid.length == 8) {
if (Userid.substring(0, 1) == 'u') {
args.IsValid = true;
}
else {
var regex = '^[0-9]{7}$';
var str = Userid.substring(1, 8)
if (str.search(regex) == -1) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
}
else {
args.IsValid = false;
}
}