How to validate multiple line values using JavaScript and Regular Expression.
Problem: I want to validate if my textarea contains only number. But my textarea accepts multiple Number values separated by break line.
1234
6743
2934
2134
Solutions:
- Merge the value into single line of code by replacing the end of line character with empty string
- Check if the value is number using regular expression
function isNumber(value){
var pattern = new RegExp("^[0-9]+$");
value = value.replace(/\n/g,"");
return pattern.test(value);
}
0 comments:
Post a Comment