We are going to use the regex method to validate comma separated value in this article. This function will return true or false as per your input. If the assigned value is valid then it will return true and if the assigned value is invalid then it will return the false. So using this method you can check the value we passed to this regex is a valid comma separated value or not.
Application of below code.
1. To insert value in table cell of excel file. Before insert value we have to check the value passed to function is a valid value or not.
2. To check the passed value to regex is a numeric value or a non numeric value.
<script> let regex = /[0-9]+(,[0-9]+)*/g console.log('1231232,12323123,122323',regex.test('1231232,12323123,122323')); console.log('1,22,34,25,645,',regex.test('1,22,34,25,645,')); console.log('1',regex.test('1')); </script>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.