2

I'm using the jQuery Clean Calendar Plugin, and it's working well. However, in my jQuery code, I want to check whether any '/' is present in textbox.val(). Then I want to do some operations. How do I check if the value contains '/' in it?

2
  • 2
    I can't tell you how much this question depresses me. Commented Jun 15, 2009 at 11:45
  • 7
    Annakata, that's not very constructive, is it? He's clearly just getting familiar with jQuery, and likely programming as a whole. I mean no disrespect, but lets encourage those who are new to the field. We were once where they are too. Commented Jun 15, 2009 at 11:47

2 Answers 2

3

Try

   if (textbox.val().indexOf( "/") >= 0)
   {
   }

Same I guess will work for attribute:

   if ($( "#id").attr( "some_attr").indexOf( "/") >= 0)
   {
   }
Sign up to request clarification or add additional context in comments.

Comments

1

Just to suggest a slightly more concise way to do it, using ternary and match() instead:

$( "#id").attr( "some_attr").match('/') ? alert('got a forward slash') : alert('no forward slash');

2 Comments

I love the ternary operator, but I'm thinking it may confuse the original poster. He seems relatively new to programming, and the if/then structure might make more sense than the () ? : ; structure.
@Jonathan - I totally agree with you. I just felt like suggesting it as no-one else had, and to introduce a bit of variety.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.