Reputation: 379
I would like to have a validation for a particular string but it can't end up with a period/dot, how could you achieve that?
Valid string:
Invalid string:
Upvotes: 0
Views: 799
Reputation: 16072
It would be much simpler to use the endsWith
method:
var validString = '.string';
var invalidString = 'string.';
validString.endsWith('.'); //false
invalidString.endsWith('.'); //true
Upvotes: 2
Reputation: 22845
The pattern you are looking for is /[^.]$/
.
However, I must ask: does it need to be regex? If not, you can just read the last character and compare it to "."
.
Upvotes: 3