Create regex controller to format input without double . and ,

This commit is contained in:
benguozakinci@gmail.com
2021-07-02 14:59:33 +03:00
parent 327d8ea94d
commit 165f857849
2 changed files with 68 additions and 39 deletions

BIN
resources/assets/js/views/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -29,15 +29,32 @@ const app = new Vue({
return { return {
form: new Form('item'), form: new Form('item'),
bulk_action: new BulkAction('items'), bulk_action: new BulkAction('items'),
regex_condition: [
'..',
'.,',
',.',
',,'
]
} }
}, },
watch: { watch: {
'form.sale_price': function (newVal, oldVal) { 'form.sale_price': function (newVal, oldVal) {
if (newVal != '' && newVal.search('^(?=.*?[0-9])[0-9.,]+$') === -1) { if (newVal != '' && newVal.search('^(?=.*?[0-9])[0-9.,]+$') == -1) {
if(newVal.search('(?<!.).(?!.)') === -1){
this.form.sale_price = oldVal; this.form.sale_price = oldVal;
} }
let splice_value;
if (newVal.search('^(?=.*?[0-9])[0-9.,]+$') == 0) {
for (let item of this.regex_condition) {
if (this.form.sale_price.includes(item)) {
splice_value = this.form.sale_price.replace(item, '');
this.form.sale_price = splice_value;
}
}
} }
}, },
@ -45,6 +62,18 @@ const app = new Vue({
if (newVal != '' && newVal.search('^(?=.*?[0-9])[0-9.,]+$') == -1) { if (newVal != '' && newVal.search('^(?=.*?[0-9])[0-9.,]+$') == -1) {
this.form.purchase_price = oldVal; this.form.purchase_price = oldVal;
} }
let splice_value;
if (newVal.search('^(?=.*?[0-9])[0-9.,]+$') == 0) {
for (let item of this.regex_condition) {
if (this.form.purchase_price.includes(item)) {
splice_value = this.form.purchase_price.replace(item, '');
this.form.purchase_price = splice_value;
}
}
}
} }
}, },
}); });