I've to develop a javascript code for validation of code factor format. The input lenght should not be greater than 3 characters long. The last character must be either 'M' or any digit between 0-9. eg. 4M or 110 or 45
The format of code factor is like this::
1. only 3 characters long
I've done this by adding maxlength
2. if all three characters are digits than number must not be greater than 150
3. if the last digit is M the number must be less than 12 i.e 11M or 4M but not 12M or 13M
From your description and based on your needs, I write some code for your reference.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(function () {
$("#txtcode").change(function () {
var codevalue = $(this).val();
alert(codevalue);
var lastnumber = codevalue.substring(2);
var pretwonumber = codevalue.substring(0, 2);
alert(pretwonumber);
alert(lastnumber);
var reg = new RegExp('\\D')
if (lastnumber != "M" && reg.test(lastnumber)) {
alert(" The last character must be either 'M' or any digit between 0-9");
}
if (lastnumber == "M") {
var inttypevalue = parseInt(pretwonumber);
if (inttypevalue >= 12) {
alert("if the last digit is M the number must be less than 12 i.e 11M or 4M but not 12M or 13M");
}
}
});
})
</script>
<asp:TextBox ID="txtcode" runat="server" AutoCompleteType="Disabled" MaxLength="3"></asp:TextBox>
scala_1988
2. if all three characters are digits than number must not be greater than 150
I am not clear about you need above. you could add code to above code based on you second requirement or provide more description about this.
Best Regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
42 Points
184 Posts
validation of code factor
Jan 27, 2017 11:27 AM|scala_1988|LINK
I've to develop a javascript code for validation of code factor format. The input lenght should not be greater than 3 characters long. The last character must be either 'M' or any digit between 0-9. eg. 4M or 110 or 45
The format of code factor is like this::
1. only 3 characters long
I've done this by adding maxlength
2. if all three characters are digits than number must not be greater than 150
3. if the last digit is M the number must be less than 12 i.e 11M or 4M but not 12M or 13M
Please help!!!
Star
8670 Points
2882 Posts
Re: validation of code factor
Jan 30, 2017 06:14 AM|Cathy Zou|LINK
Hi scala_1988,
From your description and based on your needs, I write some code for your reference.
I am not clear about you need above. you could add code to above code based on you second requirement or provide more description about this.
Best Regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.