2

I just have a quick question, im wondering if someone could help me.

I have the following script that someone has written which returns an error if there are no characters in the text field.

I want to modify the script so that it returns an error if there are less than 4 characters, but im not quite sure how.

Current script is as follows:

    if(!isString($.trim(iUsername.val()))){ //If username is not correct
        iUsername.siblings('.error').text('You must enter a username.');
        error = true;
    }
2
  • your title and your post body are contradicting; "larger" vs "less"
    – tekknolagi
    Commented Oct 22, 2011 at 3:55
  • @BigJobbies see jsfiddle.net/VvD4s
    – Ray Toal
    Commented Oct 22, 2011 at 4:13

1 Answer 1

9

if ($(textId).val().length < 4) { err; }

right? :)

3
  • This isnt working if(!isString($.trim(iUsername.val().length < 4))){
    – BigJobbies
    Commented Oct 22, 2011 at 3:59
  • 2
    tekknolagi's answer did not have isString nor trim. Try the answer as given (but put the parens after val of course).
    – Ray Toal
    Commented Oct 22, 2011 at 4:02
  • 1
    You need a () after val. After fixing it, it will be a +1.
    – Ray Toal
    Commented Oct 22, 2011 at 4:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.