/    Sign up×
Community /Pin to ProfileBookmark

TextBox validations with Reguler expressions

hi
I am trying to to validate a text box using javascript reguler expressions.
what i am trying to do is text box value must start with $ symbol and after $ symbol text box must validate numbers only.
please help me for this,i need it urgent.

thank you.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@disgracianJan 06.2007 — [b]var regEx = /^$d{1,}/;[/b] would probably work. I'm not sure if you have to escape the '$' symbol with a preceding backslash or not.

To use this to actually validate a string of text, use [b]regEx.test([i]variable_name[/i]);[/b] and this will return true if the string matches the regular expression and false if it doesn't.

Cheers,

D.

EDITED TO ADD: If you're working with currency which it seems you are, you're probably going to want to add a decimal point at some stage, in which case I'd modify the above to read:

[b]/^$d*(.d{2})?$/[/b]
Copy linkTweet thisAlerts:
@forty2Jan 06.2007 — @disgracian your regular expression return true:

$.23

$a12

and return false

$123.345

$10.1
<i>
</i>/^$d+(?:.d+)?$/
Copy linkTweet thisAlerts:
@OverstatementJan 06.2007 — disgracian seemed to have misplaced one of his shashes () one character to the left. What he really meant was:
<i>
</i>/^$d*(.d{2})?$/

I think $.23 is a valid was of writing a number but most people probably don't use $123.456
Copy linkTweet thisAlerts:
@disgracianJan 07.2007 — I did indeed misplace one of my backslashes. I am a bit dyslexic when it comes to regular expressions.

Cheers,

D.
×

Success!

Help @gpbodapati 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.19,
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,
)...