Validation on special codes [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a special ID in the format of A000000004..A000000150 etc and OD000000001..OD000000150. I have read the forums here and tried out the solutions (many in the form of /^([A]{1}\[0-9]{9})$/ etc.) but none of them have helped.

I hope I'm understanding your question properly, but how about this regex?
/^(A|OD)[0-9]{9}$/
To check a string against this regex, you'd use something like this:
var regex = /^(A|OD)[0-9]{9}$/;
if (regex.test(myCode)) {
// ... do something ...
}

***So the final solution to my question for people who will refer in future:
The code will be:
var regex= /^(A|OD)[0-9]{9}$/;
var myCode=document.forms["formname"]["fieldname"].value;
if(!regex.test(myCode))
{
alert(...);
return false;
}

Related

How to set variable of image src and use in javascript function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
So if i have some codes like this
If(sceneA){document.getElementById("divA").src="A.png";}
If(document.getElementById("divC")=="A.png"){document.getElementById("divB").src="B.png";}//And alot of codes here
How can I use a var to shorten strings like
document.getElementById("divA").src="A.png"
document.getElementById("divB").src="B.png"
so i can use them both inside (IF) and {function}
As they have to repeat quite a few times in the codes.
Thanks alot!
That's exactly what functions are for.
Define a function for repeating blocks of code as follows:
function setSrc(divName, imgName){
document.getElementById("div"+divName).src = imgName+".png";
}
function srcEquals(divName, imgName){
return (document.getElementById("div"+divName).src == imgName+".png");
}
Then you can replace your code with this:
if(sceneA){setSrc("A","A");}
if(srcEquals("C", "A")){setSrc("B","B");}

Show results of multiple prompt boxes using Javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to make multiple prompt boxes and sort their input alphabetically and then show on screen using JavaScript ?
Thanks
Sequentially
if you are talking about the almost obsolete native javascrtipt function prompt() then:
var array=[];questions=['A?','B?','C?'],current=0;
function q(question){
array.push(prompt(question,'write here')+' question number:'+current);
if(current<questions.length){
next()
}else{
array.sort()// needs a proper sort function
alert(array.join("\n"));
};
}
function next(){
q(questions[current++]);
}
next();
Demo
http://jsfiddle.net/c7GnX/

Replace javascript on Google Chrome [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an event:
javascript: AbrePesquisa ('/page/Test.asp?parm1=False');
The AbrePesquisa
function:
AbrePesquisa function (url)
{
url = url.replace = ("?" , "$$$");
...
}
In the IE, the url is coming with "$$$" ('/page/Test.asp$$$parm1=False') but it comes in chrome with "$$" ('/page/Test.asp$$parm1=False').
Why is this happening?
If you look at the docs for String.prototype.replace you'll see that $ is a special character used to include parts of the matched string in the replacement. To get what you want, you'll have to do url.replace("?", "$$$$$$");

Correct inputs for this? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to take a survey you can say: I am asking a question if they work out a lot or not, then I have different questions for them if they do or don't work out a lot. And then I am asking them if they are female or male. My goal is to give them feedback based on all three things, sex,work out or not, and how they answer questions.
Currently all of my questions go to the same inputs, for the 2 sets of questions. My code is to long to post so I will add a fiddle below .
$('.myOptions').change(function () {
$('.list').removeClass('active');
$('.' + this.value).addClass('active');
});
http://jsfiddle.net/7xM2f/12/
Your braces are not properly nested. For example you have something like
if (tt == 'Male') {
//some code
if (tt == 'Female') {
You are missing the closing brace for the Male block.
There are several such errors. You should properly indent your code to make these easier to track and pay attention to the error console.
http://jsfiddle.net/ExplosionPIlls/7xM2f/15/

How to find a certain class using .find() or some jQuery Syntax? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
if( hasWhiteSpace($(this).find(".nospace:input").val()) ){
$(this).find(".nospace:input").filter(function() {
return hasWhiteSpace(this.value) == true;
}).addClass("blank");
setError(".motd_register_company","There must be no space in between.");
return false;
}
There is something wrong about my code above, and the code only validate the first input, while the others not, how could I validate all the "nospace" class that I have in my form?
can you guys trim my code if there is something wrong.
Are you trying to recursively search elements for a particular classname? If so:
$('input.class_name').each(function() {
// Do you stuff to this input element
});
jQuery.each("input.nospace", function(i, el){
var self = $(el);
if(hasWhiteSpace(self.val()) self.addClass("blank");
});

Categories

Resources