Welcome Guest, Not a member yet? Register   Sign In
Trim first digit if its 0 validation help
#1

[eluser]Innovative[/eluser]
Hi,
I am beginner so need your help.
I have a form with phone field, if the user enters 0 as first digit then i need to trim that 0 when the field looses focus and also a gmail like or any fancy alert informing abt the change is to be accomplished. Pls suggest.
#2

[eluser]renownedmedia[/eluser]
Add zero to it.

005 + 0 = 5
#3

[eluser]Innovative[/eluser]
Can you plz give sample script for this.
#4

[eluser]renownedmedia[/eluser]
No
#5

[eluser]LuckyFella73[/eluser]
Javascript has no trim function but you can get the same
effect by using the function below.

Source: http://www.evocomp.de/beispiele/javascript/trim.html
(german site)

Code:
<scr+ipt language="javascript" type="text/java+scr+ipt">
function trim (your_string)
{
    return your_string.replace (/^\s+/, '').replace (/\s+$/, '');
}
</scr+ipt>

Try onblur event in your form
#6

[eluser]VladSun[/eluser]
[quote author="Thomas Hunter" date="1258143538"]Add zero to it.

005 + 0 = 5[/quote]
It would work in PHP, but not in JS (because + is also the concatenation operator)

Usually, I multiply by 1, or subtract 0.
#7

[eluser]Phil Sturgeon[/eluser]
Typecasting guys.

Code:
echo '005'; // 005
echo (int) '005'; // 5
#8

[eluser]VladSun[/eluser]
[quote author="Phil Sturgeon" date="1258152201"]Typecasting guys.[/quote]

It's JS, Phil Wink
#9

[eluser]Innovative[/eluser]
Thanks for all ur comments. Also can anyone suggest me abt jQuery fancy alert
#10

[eluser]Phil Sturgeon[/eluser]
ahh, parseInt()?




Theme © iAndrew 2016 - Forum software by © MyBB