Stack Exchange
Validation in java script for @*&@ charters
I want to do validation in javascript. if the string contains @*&@ charters.
<div style="text-align:center;"><input type="submit" value="Generate MDL" align="top" style="width: 120px;" ONCLICK="gt_nextPage();"></div></td>
<script type="text/javascript">

    function gt_nextPage() {
        var e=document.getElementById("getNumber");
        var val=e.options[e.selectedIndex].value;
        window.location.replace("GenerateMDL?value="+val);
    }

</script> 


I want to check If var val contains @*&@ characters..? if yes give an alert message.
Thank You.

have a look at http://www.javascriptkit.com/javatutors/re.shtml

separate characters or this string @*&@??

Try this (match lines containing any of the characters) :
var val=e.options[e.selectedIndex].value;
var regex = new RegExp("[@&\*]");
var res = regex.test(val);
if (res == true) { 
  alert("Found")
}

If you want to match characters that follow each other, replace regex line with :
var regex = new RegExp("@&\*");


From what I understood, you want if @, & and * all of them to be present in your string. You have to use look ahead for this
var val = "abcd123&@*";
var reg = /(?=.*&)(?=.*@)(?=.*\*)/;

if (reg.test(val)) {
    alert("Found")
} else {
    alert("Not Found")
}

jsfiddle demo
If you want any of @, & or *, then change the regex to
var reg = /[&@\*]/;

jsfiddle demo
If you want the exact string @*&@ to be matched, then change the regex to
var reg = /@\*&@/;

jsfiddle demo
