Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By HeshanKaru1994
#825063
issue.PNG
issue.PNG (4.46 KiB) Viewed 2613 times
I need to add two different regex validation based on the selection of the dropdown.
User avatar
By amosbatto
#825114
The JavaScript code would be something like this:
Code: Select all
var formId = $("form").prop("id");

$("#"+formId).setOnchange( function(fieldId, newVal, oldVal) {
   var aMatch = fieldId.match(/^\[productsList\]\[(\d+)\]\[productCode\]$/);
   if (aMatch) {
      var rowNo = aMatch[1];
      //0 is the column number of the ProductType field:
      var productType = $("#productsList").getValue(rowNo, 0);
      
      if (productType == "equipment") {
          if (newVal.match(/^[A-Z]{3}$/) == null) {
              alert("Product code must be three uppercase letters.");
          }
      }
      else if  {
          productType == "services") {
          if (newVal.match(/^[A-Z0-9]{5}$/) == null) {
              alert("Product code must be five uppercase letters or numbers.");
          }
      } 
   }
}); 
Where the grid ID is productsList, and the grid contains two fields with the IDs "productType" and "productCode".

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]

A Bet365 Clone Script is essentially a ready-made […]