lisovaccaro
lisovaccaro

Reputation: 33966

Get length of input type password with Jquery?

I'm trying to get the password's length so I prevent form submition if it's too short. How is this done?

This is what I'm trying right now:

$('#registerForm input[type="password"]').val.length

Upvotes: 0

Views: 9979

Answers (5)

Techie
Techie

Reputation: 45124

You can add an id <input id="pw" type="password">

$('#pw').val().length;

or You can add a class <input class="pw" type="password">

$('.pw').val().length;

else keep it as it is and you can get the length using jquery

$('#registerForm input[type="password"]').val().length;

Hope this will help you out. If you have any questions please don't hesitate to ask. Thanks

Upvotes: 3

StaticVariable
StaticVariable

Reputation: 5283

Use this you have some error in your code

$('#registerForm input[type="password"]').val().length

Upvotes: 1

Priyank Patel
Priyank Patel

Reputation: 6996

You can do $('#txtbox').val().length; to get the length

Sample fiddle

Upvotes: 1

Kristof Claes
Kristof Claes

Reputation: 10941

val is a function, so you need to write val():

$('#registerForm input[type="password"]').val().length

Upvotes: 7

Austin Brunkhorst
Austin Brunkhorst

Reputation: 21130

You need to evalute val as a function.

$('#registerForm input[type="password"]').val().length

Upvotes: 2

Related Questions