Need Help in modifying the regex

SAS21
Tera Guru

Was trying to modify the following regex to accept the alphabets (caps and small) with/without spaces allowed at the front of the card number and at the back of the card number but its not working

 

Initial regex   /\b27(?:[ \t-]*\d){13}\b/g;   trying to modify this to accept the alphabets in case if the user enters by mistake an alphabet in front/at the end of the card number.

 

Modified Regex  /\b([A-Za-z]+)27(?:[ \t- ]*\d){13}([A-Za-z ]+)\b/g;   but this is not working.
 
Appreciate the Help

 

2 REPLIES 2

Mark Manders
Mega Patron

Will this work: /\b[A-Za-z\s]*27(?:[ \t-]*\d){13}[A-Za-z\s]*\b/g


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

its working thank you...another question for the same sceanrio. is it possible to replace only the alphabet that is before the card number  instead of replacing all the text

trying with this -match.replace(/[-\sA-Za-z]/g, '').replace(/^(\d{4})/, 'XXXX');

Input - Test Data A2765 071006 71992 

 with the above script its removing all the ( text)  and giving o/p as  XXXX07100671992 

 

Required o/p should be Test Data AXXXX07100671992 . Is it possible to replace only the first alphabet if the card number has any before or end ?