Making the MEMO field non-numeric is an excellent way to reduce the likelihood of accidental swaps with the amount field. Here's a general refactor strategy:
Validation Rules for MEMO
- Restrict MEMO to alphanumeric characters or specific formats (e.g., UUID, prefixed strings like "REF-123").
- Reject purely numeric values during validation.
UI/UX Improvements
- Add placeholders or labels to clarify the difference between MEMO and amount fields (e.g., "Enter Reference Code" for MEMO and "Enter Amount" for amount).
- Highlight invalid input in real-time.
Back-End Changes
- Update input validation logic in your back-end API or contract logic to enforce non-numeric MEMO.
- Add error handling to return clear messages if users enter a numeric MEMO.
Example
Frontend:
function validateMemo(memo) {
const isNonNumeric = /^[A-Za-z][A-Za-z0-9_-]*$/.test(memo); // Alphanumeric, must start with a letter
return isNonNumeric;
}
// Example Usage
const memoInput = "REF-12345";
if (!validateMemo(memoInput)) {
console.error("Invalid MEMO: Must not be purely numeric.");
}
Backend:
def validate_memo(memo: str):
if memo.isnumeric():
raise ValueError("MEMO must not be numeric. Please use an alphanumeric format.")
return True
# Example Usage
try:
validate_memo("12345")
except ValueError as e:
print(e) # Output: MEMO must not be numeric. Please use an alphanumeric format.
require(bytes(memo).length > 0, "MEMO cannot be empty");
require(!isNumeric(memo), "MEMO cannot be numeric");
function isNumeric(string memory str) private pure returns (bool) {
bytes memory b = bytes(str);
for (uint i; i < b.length; i++) {
if (b[i] < 0x30 || b[i] > 0x39) return false;
}
return true;
}
By combining front-end, back-end, and smart contract validations, you can ensure the MEMO field remains distinct and avoids confusion with the amount.
Steem to the Moon🚀!
- You can rent Steem Power via rentsp!
- You can swap the TRON:TRX/USDT/USDD to STEEM via tron2steem!
- You can swap the STEEM/SBD to SOL Solana via steem2sol!
- You can swap the STEEM/SBD to ETH Ethereum via steem2eth!
- You can swap the STEEM/SBD to Tether USDT (TRC-20) via steem2usdt!
- You can swap the STEEM/SBD to TRX (TRON) via steem2trx!
- You can swap the STEEM/SBD to BTS (BitShares) via steem2bts!
- Register a free STEEM account at SteemYY!
- Steem Block Explorer
- ChatGPT/Steem Integration: You can type !ask command to invoke ChatGPT
- Steem Witness Table and API
- Other Steem Tools