Skip to content

Commit

Permalink
upgrade validation
Browse files Browse the repository at this point in the history
  • Loading branch information
avernikoz committed May 15, 2024
1 parent 33276a0 commit 1f8835b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/coin/utils/validation/validation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import BigNumber from "bignumber.js";

export const CREATE_COIN_VALIDATION_REGEXP = {
COIN_NAME: /^[a-zA-Z0-9\s]+$/,
COIN_SYMBOL: /^[a-zA-Z0-9_]+$/,
TOTAL_SUPPLY: /^\d+$/,
};

/**
* Validates the coin name to be a non-empty string.
*
* @param {string} coinName - The coin name to validate.
* @return {boolean} - Returns true if the coin name is valid, otherwise false.
*/
export function validateCoinName(coinName: string): boolean {
const regex = /^[a-zA-Z0-9\s]+$/;
return typeof coinName === "string" && coinName.trim() !== "" && regex.test(coinName);
return (
typeof coinName === "string" && coinName.trim() !== "" && CREATE_COIN_VALIDATION_REGEXP.COIN_NAME.test(coinName)
);
}

/**
Expand All @@ -18,8 +25,8 @@ export function validateCoinName(coinName: string): boolean {
* @return {boolean} - Returns true if the coin symbol is valid, otherwise false.
*/
export function validateCoinSymbol(coinSymbol: string): boolean {
const regex = /^[a-zA-Z_]+$/;
const isCoinSymbolIsValid = typeof coinSymbol === "string" && regex.test(coinSymbol);
const isCoinSymbolIsValid =
typeof coinSymbol === "string" && CREATE_COIN_VALIDATION_REGEXP.COIN_SYMBOL.test(coinSymbol);

return isCoinSymbolIsValid;
}
Expand Down

0 comments on commit 1f8835b

Please sign in to comment.