isAscii Function Documentation

The isAscii function checks if the input string contains only ASCII characters. It returns true if the string is composed of ASCII characters, and false otherwise.

Import

The function can be imported using ES6 syntax from the "multiform-validator" package:

import { isAscii } from 'multiform-validator';

Alternatively, you can import the function using CommonJS syntax with require (Node.js):

const { isAscii } = require('multiform-validator');

Parameters

The function takes one parameter:

Examples

// Example 1 - Checking if the string contains only ASCII characters
const result1 = isAscii('Hello');
console.log(result1); // true

// Example 2 - Checking a non-ASCII string
const result2 = isAscii('こんにちは');
console.log(result2); // false

// Example 3 - Checking a string with only ASCII characters
const result3 = isAscii('12345');
console.log(result3); // true

// Example 4 - Checking a null value
const result4 = isAscii(null);
console.log(result4); // false

// Example 5 - Checking an undefined value
const result5 = isAscii(undefined);
console.log(result5); // false

Notes

The function expects the input value to be passed as a string. It checks each character of the string, and if any character has a character code greater than 127 (non-ASCII), the function returns false. If the input is not a string or an empty string, it throws an error.