Problem is: I have one text area in jsp file, from here I am reading value through javascript and validating if the entered value is a "number between 1-25". Below is my explanation.
1) My string should contain only number between [1-25]
2) It should not have any of the characters (spl chars/symbols) apart from numbers [1-25] at any position in the string.
for example:
12-allowed (less than 25 and greater than 1) show success_message
1@#4- not allowed, show warn_message
@14#- not allowed, show warn_message
!$%12()*& - not allowed even though number is less than 25 and greater than 1, since it contains characters apart from numbers, show warn_message.
This is what i have tried
File.jsp
<div class="row">
<div class="large-1 columns">
<input id="text_area" name="posArea" type="text"/>
</div>
</div>
MyFile.js
<script>
var pos= ($('#text_area').val());
var reg="^[1-25]$";
if(pos.match(reg)){
$('#warn_message').show();
return false;
}
if(isNaN(pos)){
$('#warn_message').show();
return false;
}
else{
$('#success_message').show();
}
</script>
This is showing warning message for any number I enter, Can anyone spot my mistake? Thanks for any help. Please comment in case you do not understand my question