We are working on a form validation code snippet where jQuery masking plugin has been used to enforce validation on user input.
Masking Pattern used with zip code field is 99999?-9999 where everything is optional after “?”.
Problem occurs when user fill up the form using autofill feature in chrome[i.e. double click on input field and select value] and submit the form. On form submission, zip code value is coming as 23455-____ which includes masking pattern characters as well i.e. hypen & underscore.
If optional characters contains Hypen (-) and underscore(_) then those needs to be removed before submitting it to server. I am trying to use regex but didn’t find anything which checks for specific characters after 5th index item and then remove those.
@Paul_Wilkins Can’t use join as “-” is a must if zip code is filled with all 9 digits. Second, it is not always digits in zip code, there are few regions where zip code is alphanumeric. For ex. zip for canada is alphanumeric. So, i need to read masking pattern first to get the index of “?” then pass this index to regular expression to remove special characters after index value.
To overcome this combinations, i was searching for a regex pattern which returns string after 5th index value. For e.g. if string is “23345-_____” then that regex should search for “-” & “_” after 5th digit.