/    Sign up×
Community /Pin to ProfileBookmark

restricting commas(,) at the front and back of text…….ur help needed again

hi……
i wan t a script that if user inputs text like

,asd,asd,as,asda,asda,

the front and back commas (,) should get removed or should get a prompt.
but this user input should be fine asd,asda,asda,asd,ad

that is…..

user shouldnot be able to input ,(comma) at the front and back of the text but inbetween it should be applicable.
i always get huge response from this site abt my questions.
please sove this query of mine asap.
thanks in anticipation.
kaleena

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@tabzterSep 01.2005 — [U]Input the following code into your document.[/U]

[I]Note:// I am assuming that the input for the text string comes from the following input text element:

<form name="frmInput">

<input type="text" name="txtInput">

</form>



although you can change this for your own actual input reference.

[/I]


[B]Using this assumption, input the following:[/B]


<script type="text/javascript">

var leadCommas = /^,*/;

var endCommas = /,*
$/;

var myStr=[U]document.frmInput.txtInput.value;[/U] // change this for your own

myStr=myStr.replace(leadCommas,"");

myStr=myStr.replace(endCommas,"");

</script>
[/QUOTE]


This will, in effect, knock off all leading and trailing commas from the string for you automatically.
Copy linkTweet thisAlerts:
@CharlesSep 01.2005 — &lt;label&gt;List&lt;input onchange="this.value = this.value.replace (/(^,)|(,$)/g, '')" type="text"&gt;&lt;/label&gt;
Copy linkTweet thisAlerts:
@kaleenaauthorSep 02.2005 — thanks
×

Success!

Help @kaleena 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.17,
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,
)...