• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Starts with () Javascript Expression

I currently need to create a Javascript expression that will search all the fields that start with a parenthesis,(.  I've never created a javascript expression and can't seem to get it right.  Can someone help.

Thanks
0
metalteck
Asked:
metalteck
1 Solution
 
leakim971PluritechnicianCommented:
using this regular expression : /^\(/.test(s);
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
http://www.w3schools.com/jsref/jsref_regexp_test.asp
http://www.w3schools.com/jsref/jsref_regexp_ncaret.asp

the parenthese is "reserved" char we escape it with \ : \(

var s = "(fdfdf";
var true_or_false = /^\(/.test(s); // true
s = "fdf(df"
true_or_false = /^\(/.test(s); // false

Open in new window

0
 
HainKurtSr. System AnalystCommented:
or just use s.substring(0,1) == "("

<script>
var s1 ="(HK)"
var s2 = "HainKurt"
alert (s1.substring(0,1) == "(") // true
alert (s2.substring(0,1) == "(") // false
</script>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now