/    Sign up×
Community /Pin to ProfileBookmark

Hi,
Is there a method like isnumeric to control a text value?
Thanks in advance,
Salim

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 04.2003 — [font=monospace]<script type="text/javascript">

<!--

String.prototype.isNumeric = function () {return !isNaN(this)}

alert ('foo'.isNumeric());

alert (Math.PI.toString().isNumeric());

// -->

</script>[/font]
Copy linkTweet thisAlerts:
@GollumAug 04.2003 — you could call parseInt and test if the number is a number

e.g.
<i>
</i>var s = "12345";
if ( !parseInt(s).isNaN() ) alert("'" + s "' is a number");
Copy linkTweet thisAlerts:
@CharlesAug 04.2003 — [i]Originally posted by Gollum [/i]

[B]you could call parseInt and test if the number is a number

e.g.

<i>
</i>var s = "12345";
if ( !parseInt(s).isNaN() ) alert("'" + s "' is a number");
[/B][/QUOTE]
[font=georgia]I suppose you could, but you would find that it doesn't work.[/font]
Copy linkTweet thisAlerts:
@kyle969Aug 04.2003 — function isDigit(c){

return((c >= "0") && (c <= "9"))

}

function isInteger(s){
var c, i;
for(i = 0; i < 5; i++)
if(!isDigit(s.charAt(i))) return false;
return true;
}
Copy linkTweet thisAlerts:
@GollumAug 04.2003 — Ahh, thankyou Charles for spotting my mistake. I guess I deserve it for not checking the code before I posted.

I like your solution though. Neat and concise.
×

Success!

Help @afsarsal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...