I have a Polymer JS code which validates GST Identification number:
<dom-module id="gst">
<template>
<div>
<label for="gstid" class="gstlabel">GSTIN</label>
<input type="text" id="gstid" name="gstid" on-submit="gstid_validation(gstid)">
</div>
</template>
<script>
Polymer({
is: 'gst',
gstid_validation: function(gstin) {
var gstin_count = length(gstin);
var pattern = "qr/\d{2}[A-Z]{5}\d{4}[A-Z][A-Z\d]Z[A-Z\d]/";
if (gstin_count !== 15 && gstin !~ pattern) {
return 'Invalid GSTIN';
}
}.
});
</script>
</dom-module>
I get the following error in console:
Uncaught SyntaxError: Unexpected token !
Can anyone please help?
Thanks in advance
As I wrote in the comment also, that is clearly a problem with the second part of your if statement, gstin !~ pattern
.
Assuming that what you want is to match a regex the correct syntax would be something like:
if (gstin_count !== 15 && pattern.text(gstin))
Please note that there are several other issues with your code. Just to name a few:
pattern
variable holds a string, not a regex. For a regex you wouldn't use the quotations as delimiters. Also modifiers go at the end of regexes.length
function, so if you don't have it customly
implemented most likely you want gstin.length