views:

60

answers:

2

Hi,

I tried of checking contains option using jquery for the birthday but its getting exception

var _dob = "4/10";
// this line doesn't work
var _adob = _dob.contains('/') ? _dob.Split('/') : _dob.Split('-');
$('#Month').val(_adob[0]);
$('#Day').val(_adob[1]);

but i can't able to split.. its resulting in error on getting _adob itself

+1  A: 

Direct Answer

indexOf(something)>-1

var _dob = "4/10";
var _adob = _dob.indexOf('/')>-1 ? _dob.split('/') : _dob.split('-');
$('#Month').val(_adob[0]);
$('#Day').val(_adob[1]);

Indirectly

You really don't need to check that the string contains that... Using a regular expression, you can split on a -, /, or . by building a character set:

var _dob = '4.10';
var _aodb = _dob.split(new RegExp('[-/.]'));
gnarf
Split should be split (*it is case sensitive and the method is with lowercase s*)
Gaby
@Gaby - ty, corrected error in copy/paste section from OP...
gnarf
hi i got one more similar issue in the past...thing is i want to check the specific url from youtube alone and show success status and others i want to skip by stating it as not valid url var _videoUrl = "http://www.youtube.com/watch?v=FhnMNwiGg5M" if (_videoUrl.contains("youtube.com")')) { alert('Valid'); } else { alert('Not Valid'); }how to check with contains similar problem for me in that too...
kart
@unknown - `_videoUrl.indexOf('youtube.com')>-1` or `==0` to make sure its the first letters, or `_videoUrl.match(/^youtube\.com/)` for the regexp way.
gnarf
+1  A: 

Try this:

var _dob = "4/10";
var _adob;
if (_dob.indexOf("/") >-1) {
    _adob = _dob.split("/");
} else {
    _adob - _dob.split("-");
}
Robert Harvey
@robert: tanq it works
kart