Jump to content

Regular Expression Problem


roco
 Share

Recommended Posts

Hello - I am hoping to get some help with the syntax for my javascript. I am using this to evaluate a series of rows and to create a variable called "qty" that is dependent on "sku" containing "PNV" at the beginning of the string(sample values are PNV676, PNV897987, XYT9878, VGG897987). If "sku" does start with "PNV" I need to add 10 to the already defined variable "On_Hnd" in "qty". If it does not start with "PNV" then just use the same value that is in "On_Hnd" for "qty".//Script herevar qty;var regex=/PNV/;var a = trim(sku.getString())if (a = regex) { qty = On_Hnd.getString()+10;} else { qty = On_Hnd.getString();}Unfortunately this does not give me a result, and I am sure it is because of the syntax as I am no expert here. Any help you could offer would be appreaciated. Thanks - roco

Link to comment
Share on other sites

You need to use String.match(), not just test for equality (you have the wrong operator for equality anyway). Also, use the ^ character to specify the start of string in your regex.

var qty;var regex=/^PNV/;var a = trim(sku.getString())if (a.match(regex)) qty = On_Hnd.getString()+10;else qty = On_Hnd.getString();

Also, make sure the classes that sku and On_Hnd are instances of have getString() as a method!

Link to comment
Share on other sites

You need to use String.match(), not just test for equality (you have the wrong operator for equality anyway). Also, use the ^ character to specify the start of string in your regex.
var qty;var regex=/^PNV/;var a = trim(sku.getString())if (a.match(regex)) qty = On_Hnd.getString()+10;else qty = On_Hnd.getString();

Also, make sure the classes that sku and On_Hnd are instances of have getString() as a method!

Hey this is great! This works much better. Thanks. I still have one issue with it though and that is that my qty field is not adding the numbers but rather concatenating strings. How do I get qty = the value of "On_Hnd" +10 ...........it must be another operater besides GetString?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...