Can you help me with this?
I want to create a function that checks if the string below (represented by var x) has values after each of the 7 dashes and returns valid or invalid
var x = 4-D-5240-P43-120-08A2-8123-0000 (valid)
Here are some examples where x is invalid:
var x = 4--5220--120-08C2-8072- (invalid)
var x = 4--5217-P41-120--8072- (invalid)
var x = --5217-P41---8072- (invalid)
I attempted the following, but it fails when there is no value:
function test() {
var str1 = "4-D-5240-P43-120-08A2-8123-0000" //works
str1 = str.split('-')
var str = "4--5240-P43--08A2-8123-0000" //error here <--
str = str.split('-')
if (str.length < 8) { alert('validation failed') }
else { alert('validation passed!') }
}