Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Issue with input field

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #151220
    Kuzyo
    Participant

    Hi, everyone. Have some problem, don’t know how to solve. I’m writing small application where I check word on screen with word that was entered in input field, after checking every next word I clears input field with s.inputField.value = “”;, but then after checking I have additional empty string before the entered word:

    "word" === " word" // false
    

    How I can empty input field in another way. Thanks for advice.

    #151223
    Alen
    Participant

    You could use replace function on the string and get rid off white-space.

    Something like this: http://codepen.io/alenabdula/pen/gtdnl

    #151260
    Kuzyo
    Participant

    Thanks, @Alen works like a charm. I can’t find courage to learn RegExp

    I have found second variant, to set input defaultValue to “”.

    #151274
    Alen
    Participant

    @Kuzyo I need to take on RegEx myself. I think it’s essential to any programmer.

    I found http://regexpal.com to be helpful.

    #151301
    Kuzyo
    Participant

    Thanks for advice. Cheers…

    #151365
    Brad Metcalf
    Participant

    We had a weird issue on a clients project where we were looking for a word and would get weirdness involved. (Later turns out it was due to their clients copy and pasting from a Word document.) If the situation could use it (like it is not incredibly too sensitive and you can afford to be lax) then indexOf is a viable work around until you find a better solution.

    MDN indexOf Documentation

    MDN indexOf Prototype (Adding support to older browsers…)

    #151496
    __
    Participant

    What is the actual application? Are you using this as a challenge (e.g., like a captcha)? Or are you just looking for a particular word in a larger string of input?

    If it’s a challenge, I would argue that it should fail.

    “word” is not the same as ” word”.

    If you’re just looking for a particular word, then use a regex. They’re not scary, and your case is very simple:

    /\bword\b/.test( ' word' );
    

    it happened

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.