Menu
Codebook LogoCodebookDocsTemplates
Design SystemsJavaScriptReactPHP
Codebook LogoCodebook
  • Docs
  • Templates
  • Design Systems
  • JavaScript
  • React
  • PHP
  • Getting Started
    • Getting Started
  • JavaScript
    • React
      • Basics
      • Context
      • Forms
      • Hooks
      • Snippets
      • Examples
        • Hide on Scroll
        • Hide Sidebar on Mobile
        • Sync State Between Tabs
      • Gatsby
        • Config
      • NextJS
        • MDX
        • Router
        • Tips
      • Styled Components
        • Basics
        • Snippets
        • Typescript
    • React Native
      • Introduction
      • Basics
      • Design Systems
      • 3rd Party Components
      • React Native Web
    • NodeJS
      • Basics
      • Async
      • package.json
      • ExpressJS
        • Error Handling
      • NestJS
        • Introduction
        • Basics
    • Typescript
      • Config
    • Vanilla JS
      • Currency
      • Validation
    • Web Components
      • Storybook
      • Integrating with ReactJS
    • jQuery
      • Best Practices
  • PHP
    • Basics
    • Snippets
    • Laravel
      • Blade
      • DevOps
      • Tips
  • CSS
    • Snippets
  • Dev Ops
    • Project Management
      • Linting
    • Git
      • Snippets
    • Ubuntu
      • Permissions
  • Other
    • Regex
    • Shopify
    • Netlify
    • Firebase
      • Introduction
      • Basics
      • Gatsby
  • Design Systems
    • Theming
      • Examples

Validation

Check for number#

Checks if string contains a number, returns boolean. via

function hasNumber(myString) {
return /\d/.test(myString);
}

Check for string#

Check variable for any text / characters (a-z) that aren't numbers. (e.g. checks if const a = '1px' contains px). via

const str = "1px";
if (/[a-z]/i.test(str)) {
// alphabet letters found
}
Previous
« Currency in JavaScript
Next
Storybook for Web Components »
  • Check for number
  • Check for string
Ryosuke logo
Copyright © 2020 Ryosuke