Jump to content

Regular Expression Problem


roco

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...