Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to jQuery. I have a text field and I want to validate this field so that it only takes character and alphanumeric values, however if you put in a numeric value it will show a message. How should I implement this?
$('#textfieldid').on('change', function(event) {
var text = $('#textfieldid').text();
//some validation code here
});
By the way, JQuery is a javascript library, not Java (which you have tagged).
Using regex, validations can be done.
var password = document.getElementB;
var letter = /[a-zA-Z]/;
var number = /[0-9]/;
if(number.test(password) && letter.test(password)){
//success
}else{
//error
}
Here password is the value which is returned from the field
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I'm not so good with regex or trying to return the side part of a string. Can someone help me figure this out. I have a demo below.
str = "<html><head><script>var x = '123';</script></head></html>";
console.log(str)
// should return var x = '123';
Someone wrote a very good regex for stripping tags:
var strippedStr = str.replace(/(<([^>]+)>)/ig,"");
console.log(strippedStr);
Source: http://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
I played around a bit with it and found a way with match using groups:
str.match(/(>)([^><]+)(<\/)/m)[2]
result = "var x = '123';"
=> a range (2nd group) beginning by ">" (1st group) and ending with "var x = '123';
I am not sure it'll cover all the cases...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Trying to add a second condition to a js function
original condition
if (content.length==elmnt.maxLength)
new condition
if (content.length==elmnt.maxLength && current form field value > 1400)
how do I code "current form field value > 1400" properly in javascript?
Full original code:
<SCRIPT TYPE="text/javascript">
function jumpField(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</SCRIPT>
Thanks!
Not sure if I fully understand what you are trying to achieve.
Are you looking for parseInt() to convert a string value? Like:
parseInt(document.forms[0].elements[next].value) > 1400
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can anyone explain what is meaning of this Regular Expression?
/^(https?):\/\/(www\.)?[a-zA-Z0-9\-\.]+\.[a-zA-Z0-9]{2,3}[a-zA-Z0-9\-\#\.\/\?]*$/
Finally I have founded my solution:
function validateURL(url)
{
var re = /^(https?):\/\/(www\.)?[a-z0-9\-\.]+\.[[a-z0-9\-\.\/]{2,}]*$/;
if (!re.test(url))
{
return false;
}
else
{
return true;
}
}
this function return true if your url contain these:
part 1. https or http
part 2. www or not (means optional).
Below image exploring in more depth.
I am wrong?
I've tried the following and works fine for me.
var url = "https://www.xyz.xe";
function validateURL(url)
{
var urlregex = new RegExp("^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*#)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");
return urlregex.test(url);
}
validateURL(url);
Returs false when url="https://www.xyz.x" and true when url="https://www.xyz.xe"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
is it possible to convert a text from an input to a string or integer?
I have an input field, in which you can search a company:
<input type="text" id="company" name="company" />
Now I need the value as a string or int.
Thanks for you help.
Value of the input field is a string by default. You can convert it to an int by
parseInt(document.getElementById("company").value,10);
It is Simple stuff. You can convert by using parseInt() Function.
It will convert your string to Integer.
function convert()
{
var x=document.getElemenyById("company").value;
x=parseInt(x);
}
jquery version:
parseInt($( "#company" ).val(), 10);
plain javascript:
parseIntdocument.getElementById('company').value, 10);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have this issue when im trying to upload a form in ie: Object doesn't support property or method 'ajaxSubmit' Here is my code:
function Upload() {
ShowWait();
uploadCompleted = false;
$(document.forms[0]).ajaxSubmit({ success: PostUploadProcess });
intervalHandler = setInterval(function () {
var responseText = $("iframe").contents().find("body").html();
if (responseText)
PostUploadProcess(responseText);
}, 1000);
return false;
}
Can anyone help me?
http://malsup.com/jquery/form/
needs to be separately included. its not part of jquery core.