Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string starts with a number [duplicate]

Tags:

How would I do something like this in javascript:

var s = '124sdg'; var f = 'hsdsda'; if (s.startsWith(a number)) {    // Return true } if (f.startsWith(a number)) {    // Return false } 
like image 492
Coomphs Avatar asked Sep 28 '16 00:09

Coomphs


People also ask

How do you check if a string starts with a digit in Python?

Python String isdigit() The isdigit() method returns True if all characters in a string are digits. If not, it returns False .

How do you check if a string starts with zero?

You can do something like: if ( str. startsWith("00") && ! str.


1 Answers

You can use a regular expression:

if (s.match(/^\d/)) {    // Return true } if (f.match(/^\d/)) {    // Return false } 
like image 168
redneb Avatar answered Sep 18 '22 12:09

redneb