 |
Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 18th, 2005, 09:48 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
check if first char is a letter
Code:
seat_zelle.innerHTML = "<input type=text id=specify"+s+" name=specify"+s+" class=selects size=5 onKeyUp='this.value=this.value.toUpperCase();'/>";
I am building this textbox in innerHTML, how can i put a condition on it so that it detects what is inputted so that if the first char that is entered
is a LETTER then it alerts the user?
Picco
www.crmpicco.co.uk
|

October 18th, 2005, 10:32 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
onKeyUp='this.value=this.value.toUpperCase();' if(/^[a-z]/i.test(this.value)){alert(\"first char is a letter\")};'
HTH,
Chris
|

October 19th, 2005, 11:34 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for that chris, have you got a function that will check if AT LEAST ONE character in a textbox is a letter?
www.crmpicco.co.uk
|

October 20th, 2005, 04:54 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sure...
Code:
onkeyup="if(/^.*[a-z].*/i.test(this.value)){alert('at least one letter')};"
If you're going to be doing a lot of string comparisons, I'd highly recommend a look at regular expressions.
Cheers,
Chris
|

October 20th, 2005, 05:20 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks again chris, trying to think of a function name. ive got function IsNumeric(sText,id) to check for numeric fields IsAlpha is A-Z AND 0-9 got a name for letters only (A-Z) :-) LOL
www.crmpicco.co.uk
|

October 20th, 2005, 05:25 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='containsLetter(this.value,this.id); concatSeats(this.value,"+passNo+",this.id,"+pass+");' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
function containsLetter(sText,id)
{
if(/^.*[A-Z].*/i.test(this.value))
{
alert("The Seat must contain at least one letter");
return false;
}
}
Can't seem to get it working with this code above???
www.crmpicco.co.uk
|

October 20th, 2005, 05:39 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='if(!/^.*[a-z].*/i.test(this.value)){alert('The Seat must contain a letter')}; concatSeats(this.value,"+passNo+",this.id,"+pass+");' "+
"onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
Getting an syntax error with this code.
Doesnt seem to like anything inside quotes for the alert. Can i send it to a fucntion to check then alert?
www.crmpicco.co.uk
|

October 20th, 2005, 05:42 AM
|
Friend of Wrox
|
|
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Code:
seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
"title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
"class='selects' size='5' onBlur='if(!/^.*[a-z].*/i.test(this.value)){alertUser();}; concatSeats(this.value,"+passNo+",this.id,"+pass+");' "+
"onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
function alertUser()
{
alert("The Seat must contain a letter for the row identifer");
return false;
}
this works, but can i do the validation and the alert in one function?
thanks.
picco
www.crmpicco.co.uk
|
|
 |