I use following code to check if a user input is lowercase or not. I will allow characters from a
to z
. no other characters allowed.
JavaScript file:
var pat = /[a-z]/;
function checkname()
{
var t = $("input[name='user_name']").val();
if(pat.test(t) == false)
{
alert('Only lowercase characters allowed');
}
}
//... other functions
But this donot work all the time. If I enter industrialS
, it will not find that capital 'S'.
I also tried: /^[a-z]$/
and /[a-z]+/
. But not working.
PLease help me.
Your regular expression just checks to see if the string has any lower-case characters. Try this:
var pat = /^[a-z]+$/;
That pattern will only match strings that have one or more lower-case alphabetic characters, and no other characters. The "^" at the beginning and the "$" at the end are anchors that match the beginning and end of the tested string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With