regex was broken

This commit is contained in:
EthanHealy01 2025-09-17 20:39:36 +01:00
parent 59feaddc9c
commit dfbc29811f
2 changed files with 7 additions and 8 deletions

View File

@ -7,7 +7,8 @@ import { RemovePagesParameters, defaultParameters } from './useRemovePagesParame
export const buildRemovePagesFormData = (parameters: RemovePagesParameters, file: File): FormData => {
const formData = new FormData();
formData.append('fileInput', file);
formData.append('pageNumbers', parameters.pageNumbers);
const cleaned = parameters.pageNumbers.replace(/\s+/g, '');
formData.append('pageNumbers', cleaned);
return formData;
};

View File

@ -6,20 +6,18 @@ export const validatePageNumbers = (pageNumbers: string): boolean => {
const parts = normalized.split(',');
// Regular expressions for different page number formats
const singlePageRegex = /^\d+$/; // Single page: 1, 2, 3, etc.
const rangeRegex = /^\d+-\d*$/; // Range: 1-5, 10-, etc.
const negativeRegex = /^-\d+$/; // Negative: -3 (last 3 pages)
const mathRegex = /^\d*[n]\d*[+\-*/]\d+$/; // Mathematical: 2n+1, n-1, etc.
const allToken = /^all$/i; // Select all pages
const singlePageRegex = /^[1-9]\d*$/; // Single page: positive integers only (no 0)
const rangeRegex = /^[1-9]\d*-(?:[1-9]\d*)?$/; // Range: 1-5 or open range 10-
const mathRegex = /^(?=.*n)[0-9n+\-*/() ]+$/; // Mathematical expressions with n and allowed chars
return parts.every(part => {
if (!part) return false;
return (
allToken.test(part) ||
singlePageRegex.test(part) ||
rangeRegex.test(part) ||
negativeRegex.test(part) ||
mathRegex.test(part)
);
});
};