My Search "function" Does Not Work
var cat = prompt('What Do You Want To Tweet??!'); if(cat.length >= 140) { confirm('Sorry but your Tweet was over the 140 character limit by: ' + (cat.length - 140)); confirm(
Solution 1:
You could do more accurate search by using jQuery. The '.inArray()' function should do the trick.
http://api.jquery.com/jquery.inarray/
<!doctype html><htmllang="en"><head><metacharset="utf-8"><title>jQuery.inArray demo</title><style>div {
color: blue;
}
span {
color: red;
}
</style><scriptsrc="//code.jquery.com/jquery-1.10.2.js"></script></head><body><div>"John" found at <span></span></div><div>4 found at <span></span></div><div>"Karl" not found, so <span></span></div><div>"Pete" is in the array, but not at or after index 2, so <span></span></div><script>var arr = [ 4, "Pete", 8, "John" ];
var $spans = $( "span" );
$spans.eq( 0 ).text( jQuery.inArray( "John", arr ) );
$spans.eq( 1 ).text( jQuery.inArray( 4, arr ) );
$spans.eq( 2 ).text( jQuery.inArray( "Karl", arr ) );
$spans.eq( 3 ).text( jQuery.inArray( "Pete", arr, 2 ) );
</script></body></html>
Solution 2:
You can try using regular expressions
var cat = prompt("What Do You Want To Tweet??!"),
expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi,
regex = newRegExp(expression);
if(cat.length >= 140) {
confirm("Sorry but your Tweet was over the 140 character limit by: " + (cat.length - 140));
confirm("You need to resubmit a Tweet that is not over the 140 Character limit");
}
else{
confirm("Success, Your Tweet has been posted!");
}
//scan for websitesif (cat.match(regex)) {
confirm("We have dectected a URL in your Tweet");
}
else{
confirm("no URL");
}
Post a Comment for "My Search "function" Does Not Work"