mardi 20 octobre 2020

Force users to type or paste correct form of string. Problem with inverting reg ex

I would like to force users to type or paste correct form of string like: a001 a025 F190 F500 GND UNL SFC

I've made a pattern to detect this type:

/(gdn|GND|unl|UNL|sfc|SFC)|(a|A|f|F)[0-9]{1,3}/g

However it need to be opposite/ inverted regular expression to replace everything not matched by my script:

checkAltitudePattern(e,i,control) {
    let val: string = e.target.value.toUpperCase();
    let pattern = /(gdn|GND|unl|UNL|sfc|SFC)|(a|A|f|F)[0-9]{1,3}/g;
    let patternVal = val.replace(pattern, "");
    //console.log("patternVal",patternVal)
    if (control === 'lowerAltitude') {
        this.AltFromControl(i).patchValue(patternVal);
    } else if (control === 'upperAltitude') {
        this.AltToControl(i).patchValue(patternVal);
    }
}

I would be gratefull if anyone could help. Regards

Aucun commentaire:

Enregistrer un commentaire