Check out example codes for "formula regex para validar cpf e cnpj no google forms". It will help you in understanding the concepts better.

Code Example 1

([0-9]{2}[\.]?[0-9]{3}[\.]?[0-9]{3}[\/]?[0-9]{4}[-]?[0-9]{2})|([0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2})

Learn ReactJs, React Native from akashmittal.com