You can try this regex:
/^(!?--\s*[Ss]elect\s*--)$/
You should also find SelectedIndex property to evaluate this item.
Question
I have a dropdown in which I am having
"-- Select--"
as the first item. I want to check if user has choosen something else from the dropdown instead of Select. So is there a way around to match if !-- Select --. I have done this till now.
"regex": /^[!-- Select --]$/,
Where "!" means when not Select. I am achieving this client side.
La solution
You can try this regex:
/^(!?--\s*[Ss]elect\s*--)$/
You should also find SelectedIndex property to evaluate this item.
Autres conseils
It doesn't work because you're using a big character class; instead of trying to match the opposite, try to match what you don't want and then logically reverse that.
/^[-]{2} Select [-]{2}$/
function selectavalue() {
var selectBox = document.getElementById('selectboxid');
var user_input = selectBox.options[selectBox.selectedIndex].innerHTML;
var str = user_input;
if((str.match(/--Select--/i)) )
{
alert("Please select a value");
}
else
{
alert("The value u selected is"+str);
}
}
call this function from your selectbox.onchange="return selectavalue();"
You can use jQuery
if($("#id of your select box").attr("selectedIndex") == 0)
{
alert("You haven't selected anything!");
}
You have to make first value as default value.