Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for matching values in a string

Status
Not open for further replies.

rmagan

Programmer
Jun 3, 2003
35
US
I have a form that accepts a field(p_chg_semester).
I need to check the value of p_chg_semester to see if it exists in the string (field_string). For example.
If the sample below a value of '*G*' would be one of the valid entries.



field_string = '*A**B**C**D**F**G**H**I**J**K*';
<input type=&quot;text&quot; name=&quot;p_chg_semester&quot; onChange=&quot;IsValidSemester(this.value)&quot;>);
 
<html>
<head>
<script language=&quot;javascript&quot;>
function huh() {
var objRE = /*G*/;
var field_string = '*A**B**C**D**F**G**H**I**J**K*';
if (objRE.test(field_string)) {
document.write(&quot;Found!&quot;);
}
else
{
document.write(&quot;Not found!&quot;);
}
}
</script>
</head>
<body onload=&quot;huh();&quot;>
</body>
</html>
 
Sorry there's a small mistake....
Should be:
var objRE = /\*G\*/;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top